I created two forms in Microsoft Access 2010: let's call them Form1 and Form2.
A Button on Form1 is supposed to call Form2. Form2 has two option buttons that are inside and optiongroup form, and two buttons, one of which is cancel. I created the following code which worked perfectly for a while:
Private Sub cmdCancel_Click()
DoCmd.Close acForm, Me.Name
End Sub
Private Sub cmdCreateFactsheet_Click()
Dim sFund As String
If Me.OptionGroup = 2 Then
On Error Resume Next
sFund = Me.ComboFundliste.Value
On Error GoTo 0
If sFund = "" Then
MsgBox ("Please select a Fund")
End
Else
Call modAdvisoryFactSheet.FactSheetSelection(sFund)
End If
End If
End Sub
Private Sub frmSelection_Open()
Me.OptionGroup.DefaultValue = 1
End Sub
Private Sub OptOneFund_GotFocus()
If Me.OptionGroup = 2 Then
Me.ComboFundliste.Enabled = True
End If
End Sub
Private Sub OptAllFunds_GotFocus()
If Me.OptionGroup = 1 Then
Me.ComboFundliste.Value = ""
Me.ComboFundliste.Enabled = False
End If
End Sub
Now, every single Sub produces an error when I try to open form2, or if I open form2 manually, when I try to klick on any of the controls.
The message is always the same: The expression On Click you entered as the event property setting produced the following error: variable not defined
I realize this must have something to do with how I reference the form, but I don't understand why this worked well and then suddenly stopped working. I didn't change anything as far as I can remember and I don't see what is wrong!
Any help appreciated.
This answer really belongs to Matt Hall. Matt, if you want to answer it, I'd be happy to give you the checkmark. For the time being, I'll put this up so it's clear what the solution was:
I had to run Debug>Compile in order to see the line that caused the error. It turned out that I had a Variable in a Sub several level down, that wasn't properly defined.