If checkbox = True Then DoCmd.OpenForm "NOT WORKING"

  • Thread starter Thread starter JNariss
  • Start date Start date
J

JNariss

I have a form with many checkboxes. It is actually a Main Menu form
with some checkboxes already checked as default selections and others
the users can choose from.

Depending on what the users select, some selections have another form
that goes with them. So if my user puts a check next to checkbox A (for
example) I would like form A to open.

I have found out the code for this should go behind the After Update
event. So here is the code I am using:

Private Sub Ctl1001_BPCS_Production_Data_Base_AfterUpdate()
If Me.[Ctl1001_BPCS_Production_Data_Base] = True Then
strFormName = "[frmAppCodeMenu]"
End If
DoCmd.OpenForm strFormName, acNormal
End Sub


My checkbox name is: Ctl1001_BPCS_Production_Data_Base
My form name to have opened if the checkbox is "true" is:
frmAppCodeMenu

Whenever I preview my form and put a check in the checkbox I get the
following error:

The expression After Update you've entered as the event property
setting producted the following error: object or class does not support
the set of events.

Does anyone know what is happening here and how I can make this work
correctly??

Thanks,
Justine
 
Assuming that you have declared your variable: strFormName correctly:
Dim strFormName as String

Then, try removing the square brackets around your control name and also the
name of your form you want to open.

Private Sub Ctl1001_BPCS_Production_Data_Base_AfterUpdate()
If Me.Ctl1001_BPCS_Production_Data_Base = True Then
strFormName = "frmAppCodeMenu"
End If
DoCmd.OpenForm strFormName, acNormal
End Sub
 
The brackets around the control name are okay, Around the form name is a
problem. There is also problem is where the End If is located. As written,
it will attempt to open a form regardless of the value of the check box.
This will create another error.
Should be
Private Sub Ctl1001_BPCS_Production_Data_Base_AfterUpdate()
Dim strFormName As String

If Me.Ctl1001_BPCS_Production_Data_Base = True Then
strFormName = "frmAppCodeMenu"
DoCmd.OpenForm strFormName, acNormal
End If

End Sub

See how proper indentation makes the code more readable?
One other point. Unless I am using logic to determine which form or report
to open, I don't put it in a varialbe. Just extra code and memory. I would
do it like this:
Private Sub Ctl1001_BPCS_Production_Data_Base_AfterUpdate()

If Me.Ctl1001_BPCS_Production_Data_Base = True Then
DoCmd.OpenForm "frmAppCodeMenu", acNormal
End If

End Sub

Mr B said:
Assuming that you have declared your variable: strFormName correctly:
Dim strFormName as String

Then, try removing the square brackets around your control name and also the
name of your form you want to open.

Private Sub Ctl1001_BPCS_Production_Data_Base_AfterUpdate()
If Me.Ctl1001_BPCS_Production_Data_Base = True Then
strFormName = "frmAppCodeMenu"
End If
DoCmd.OpenForm strFormName, acNormal
End Sub

--
HTH

Mr B


I have a form with many checkboxes. It is actually a Main Menu form
with some checkboxes already checked as default selections and others
the users can choose from.

Depending on what the users select, some selections have another form
that goes with them. So if my user puts a check next to checkbox A (for
example) I would like form A to open.

I have found out the code for this should go behind the After Update
event. So here is the code I am using:

Private Sub Ctl1001_BPCS_Production_Data_Base_AfterUpdate()
If Me.[Ctl1001_BPCS_Production_Data_Base] = True Then
strFormName = "[frmAppCodeMenu]"
End If
DoCmd.OpenForm strFormName, acNormal
End Sub


My checkbox name is: Ctl1001_BPCS_Production_Data_Base
My form name to have opened if the checkbox is "true" is:
frmAppCodeMenu

Whenever I preview my form and put a check in the checkbox I get the
following error:

The expression After Update you've entered as the event property
setting producted the following error: object or class does not support
the set of events.

Does anyone know what is happening here and how I can make this work
correctly??

Thanks,
Justine
 
Wow....this is great!! I really appreciate your help. I had a busy day
today working on another database so tomorrow I will try the code you
have provided and see what happens.
 
You guys are fantastic......................the code works perfectly!!!

Thanks a million!!!
 
Back
Top