Command Button Problem

M

MB

I have a form for data entry with the record source tblBreakInfo. Allow
Additions, Deletions, Edits and Filters are set to “Yes.â€

When I add a command button, such as “Quit Application†it does not work. I
have changed the form’s “Allow Edits†to No and it still won’t work. The “On
Click†property of the button says Event Procedure and has the following VBA:

Private Sub cmdQuit2_Click()
On Error GoTo Err_cmdQuit2_Click

If Me.Dirty Then Me.Dirty = False
DoCmd.Quit

Exit_cmdQuit2_Click:
Exit Sub

Err_cmdQuit2_Click:
MsgBox Err.Description
Resume Exit_cmdQuit2_Click

End Sub

I have this problem with any command button I add (i.e., new record). It
works if I create a macro to close program or go to new record, but not a
command button with the wizard. I am using Access 2007.

Thank you so much for your assistance.
 
A

Allen Browne

Code does not run unless your
database is in a trusted location.

To trust your folder, click:

a.. Office Button (top left)
b.. Access Options (bottom of dialog)
c.. Trust Center (left)
d.. Trust Center Settings (button)
e.. Trusted Locations (left)
f.. Add new location (button)
 
M

MB

Thank you, Allen. I secured the location; however when I now open the
database, I get an error (Run Time error '2465') saying Access cannot find
"OptionsLable1" and the debug shows the following with the following line
highlighted: Me("OptionLabel" & rs![ItemNumber]).Visible = True

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this switchboard
page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
rs.MoveNext
Wend
End If

' Close the recordset and the database.
rs.Close
Set rs = Nothing
Set con = Nothing

End Sub
 
A

Allen Browne

In the code window, choose Compile on the Debug menu.

That should take you to the line causing the problem.

Could also be a references problem:
http://allenbrowne.com/ser-38.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

MB said:
Thank you, Allen. I secured the location; however when I now open the
database, I get an error (Run Time error '2465') saying Access cannot find
"OptionsLable1" and the debug shows the following with the following line
highlighted: Me("OptionLabel" & rs![ItemNumber]).Visible = True

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this
switchboard
page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
rs.MoveNext
Wend
End If

' Close the recordset and the database.
rs.Close
Set rs = Nothing
Set con = Nothing

End Sub
--
Looks like a switchboard problem, but I don't know the fix. Can you help
with that, too? Thank you again for your time.

MB


Allen Browne said:
Code does not run unless your
database is in a trusted location.

To trust your folder, click:

a.. Office Button (top left)
b.. Access Options (bottom of dialog)
c.. Trust Center (left)
d.. Trust Center Settings (button)
e.. Trusted Locations (left)
f.. Add new location (button)
 
M

MB

Hi Dirk, thanks for your help. I didn't know about the macro settings. I
changed it to enable macros regardless of location, but I still get the run
time error '2465'
saying Access cannot find "OptionsLable1" and the debug shows the following
with the following line highlighted: Me("OptionLabel" &
rs![ItemNumber]).Visible = True

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this switchboard
page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
rs.MoveNext
Wend
End If

' Close the recordset and the database.
rs.Close
Set rs = Nothing
Set con = Nothing

End Sub
 
D

Dirk Goldgar

MB said:
Hi Dirk, thanks for your help. I didn't know about the macro settings. I
changed it to enable macros regardless of location, but I still get the
run
time error '2465'
saying Access cannot find "OptionsLable1" and the debug shows the
following
with the following line highlighted: Me("OptionLabel" &
rs![ItemNumber]).Visible = True

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this
switchboard
page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
rs.MoveNext
Wend
End If

' Close the recordset and the database.
rs.Close
Set rs = Nothing
Set con = Nothing

End Sub


That sounds to me like a "righteous" error -- that is, it's probably telling
you exactly what is wrong. The code is trying to act on a label control
named "OptionLabel1", but it seems there is no control with that name on the
form. I suggest you open the form in design view and check the names of all
the label controls. Maybe you renamed the control, maybe you deleted it,
maybe it's something else that I can't think of right now.
 
M

MB

I'll checks those. Thank you again, Dirk.
--
MB


Dirk Goldgar said:
MB said:
Hi Dirk, thanks for your help. I didn't know about the macro settings. I
changed it to enable macros regardless of location, but I still get the
run
time error '2465'
saying Access cannot find "OptionsLable1" and the debug shows the
following
with the following line highlighted: Me("OptionLabel" &
rs![ItemNumber]).Visible = True

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this
switchboard
page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
rs.MoveNext
Wend
End If

' Close the recordset and the database.
rs.Close
Set rs = Nothing
Set con = Nothing

End Sub


That sounds to me like a "righteous" error -- that is, it's probably telling
you exactly what is wrong. The code is trying to act on a label control
named "OptionLabel1", but it seems there is no control with that name on the
form. I suggest you open the form in design view and check the names of all
the label controls. Maybe you renamed the control, maybe you deleted it,
maybe it's something else that I can't think of right now.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
A

Angela

I've also had problems with the command button. I got the button to bring up
my subform with the OnClick feature, however, it doesn't bring up the
information particular to the record I was working on. It brings up for all
the records and I have to find the record I was looking for. I tried the
same thing with a second form instead, and the same problem happend.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top