HELP! VBA Code Stopping on Open

Discussion in 'Access VBA Modules' started by Manuel, Jun 1, 2010.

  1. Manuel

    Manuel Guest

    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
     
    Manuel, Jun 1, 2010
    #1
    1. Advertisements

  2. Manuel

    Danny Guest

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

    "Manuel" wrote:

    > 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
     
    Danny, Jun 1, 2010
    #2
    1. Advertisements

  3. 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

    "Manuel" <> wrote in message
    news:...
    >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
     
    Jeanette Cunningham, Jun 1, 2010
    #3
  4. Manuel

    Manuel Guest

    That did the trick. Thanks!

    "Danny" wrote:

    > Community Message Not Available
     
    Manuel, Jun 1, 2010
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Mc

    Stopping the escape key being pressed.

    David Mc, Jul 21, 2003, in forum: Access VBA Modules
    Replies:
    1
    Views:
    119
    John Spencer (MVP)
    Jul 21, 2003
  2. TonyB

    Stopping movement away from a form control ?

    TonyB, Mar 14, 2005, in forum: Access VBA Modules
    Replies:
    6
    Views:
    136
    Allen Browne
    Mar 14, 2005
  3. NotMyRealName
    Replies:
    1
    Views:
    103
  4. Rob

    stopping a macro by writing the code

    Rob, Jul 18, 2006, in forum: Access VBA Modules
    Replies:
    1
    Views:
    72
    Sreedhar
    Jul 18, 2006
  5. Wendy

    Stopping empty reports from being created

    Wendy, Oct 2, 2006, in forum: Access VBA Modules
    Replies:
    1
    Views:
    93
    Douglas J. Steele
    Oct 2, 2006
  6. Rick Campbell

    Module is stopping that once worked

    Rick Campbell, Jan 5, 2007, in forum: Access VBA Modules
    Replies:
    7
    Views:
    96
    Tom Wickerath
    Jan 5, 2007
  7. Dan

    Stopping new record creation

    Dan, Feb 25, 2008, in forum: Access VBA Modules
    Replies:
    2
    Views:
    86
    Klatuu
    Feb 25, 2008
  8. Debugger not stopping at breakpoint

    , Jul 11, 2008, in forum: Access VBA Modules
    Replies:
    11
    Views:
    147
Loading...