HELP! VBA Code Stopping on Open


M

Manuel

I have a database that, when opened, launches a form (via Display Form/Page
in Startup…). For some inexplicable reason the code stops/breaks at the On
Open event and the VBA editor displays. I can’t figure out why this is
happening, it has not happened in the past and this database has been in use
for quite some time. There is NO code break set and the break only happens
once, when the form is opened for the first time. If I select F5 the code
runs and the form opens. If I close the form and then reopen it (manually by
double clicking on it) the form opens without stopping at the On Open event.
I’ve opened several other forms and none break at the On Open event.

Here’s the On Open code for the form in question. The only recent change to
this code is the addition of the following line:

Me.TabCtl2.Pages("Pct Comp").Visible = False

Private Sub Form_Open(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strUser As String
Dim bln As Boolean

strUser = loggedOnUser

Set db = CurrentDb
Set rs = db.OpenRecordset("tblSecurity")

rs.MoveFirst

While Not rs.EOF
If strUser = rs!UserName Then
bln = True
End If
If Not rs.EOF Then rs.MoveNext
Wend

rs.Close
Set db = Nothing
Set rs = Nothing

If bln = False Then
Me.TabCtl2.Pages("Metrics").Visible = False
Me.TabCtl2.Pages("Change Control").Visible = False
Me.TabCtl2.Pages("Pct Comp").Visible = False
Forms![MainForm]![Tracking_Form]![EmpNameID].Visible = False
Forms![MainForm]![Tracking_Form]![ResourceID].Visible = False
Forms![MainForm]![Tracking_Form]![lblRefresh].Visible = False
End If

End Sub

I’ve closed and opened the database several times and have run Compact and
Repair, all to no avail.

I would really appreciate if someone could provide suggestions as to why the
code is breaking when I have not set a break.

Thanks,

Manuel
 
Ad

Advertisements

D

Danny

Have you compiled the code? In the VBA window, on the main menu, select
'Debug' and then 'Compile'...
 
J

Jeanette Cunningham

Comment out the line:
Me.TabCtl2.Pages("Pct Comp").Visible = False

What happens now when you open the database?


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Ad

Advertisements


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

Similar Threads


Top