Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    On Open (Switchboard) (A2k)

    My "Switchboard" opens with a subform showing Company Information.

    I'm quite happy for the form to load but want to ensure that first time loaders enter there info before proceeding.
    The chain of events would be:

    Switchboard loads or opens.
    Check the subform to see if any company info exists.
    If not, then close the Switchboard and open the company info form.

    Here's the code I've been playing with on the Switchboards open event.
    The msgbox does popup but the Switchboard still loads as normal.
    What should I do to the following code to ensure the chain of events.

    Private Sub Form_Open(Cancel As Integer)
    ' Minimize the database window and initialize the form.
    ' Move to the switchboard page that is marked as the default.
    Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
    Me.FilterOn = True
    ClockName = 1
    DoCmd.Maximize
    'Check to see if company info is filled in on frmCompany
    If IsNull(Me!frmCompany.Form.Company) Then
    MsgBox "You Must Enter Your Company Information To Proceed", vbOKOnly
    If vbOKOnly Then
    DoCmd.Close acForm, Me.Name,acSaveNo
    DoCmd.OpenForm "frmCompany"
    End If
    End If
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: On Open (Switchboard) (A2k)

    You must set the Cancel argument of Form_Open to True to, well, cancel the opening of the form.

    "If vbOKOnly Then" is not a useful statement. Since vbOKOnly = 0, the lines following it will never be executed. Try the following instead:

    If IsNull(Me!frmCompany.Form.Company) Then
    MsgBox "You Must Enter Your Company Information To Proceed", vbInformation
    Cancel = True
    DoCmd.OpenForm "frmCompany"
    End If

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: On Open (Switchboard) (A2k)

    Thanks Hans, works to a degree.

    A little inter-action with the databases "Splash" screen is causing a 2501 error.
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: On Open (Switchboard) (A2k)

    Error 2501 means that the action was canceled - because I advised you to set Cancel to True in the On Open event of the Switchboard <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Add an error handler and make it ignore error 2501:

    Private Sub Form_Timer()
    Dim stDocName As String
    Static intCount As Integer

    On Error Goto ErrHandler

    intCount = ...
    ...
    ...
    End If

    Exit Sub

    ErrHandler:
    If Err = 2501 Then
    ' Ignore 2501
    Else
    MsgBox Err.Description, vbExclamation
    End If
    End Sub

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: On Open (Switchboard) (A2k)

    Thanks again, perfect. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •