Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with report code (2003)

    I have a form where there are 4 text fields. The first two text fields are for client mgr number and an employee number. The second set of text boxes are for ASM number and their Employee number. I have these set up in a query so that they can only enter Client mgr and their employee number or an ASM can enter their number and their employee number. Now here is the problem. If they put their Client mgr number without the Client mgr employee number and vice versa - I don't want the the report to run. Same for the ASM.

    I have the following code in the report that I received from Hans for another report. I substituted my current fields - txtRepNo and txtEmpId for Client Mgr and TxtASMno and Txtempid2. I don't know how to address the different scenarios.

    On Error GoTo Err_cmdrunreport_Click

    Dim stDocName As String

    stDocName = "Rpt_for_Reps_Prompt"



    If IsNull(Me.txtEmpid) Or IsNull(Me.txtRepNo) Then
    ' Scold the user
    MsgBox "Please enter both Numbers!", vbExclamation

    Else
    If IsNull(Me.txtEmpID2) Or IsNull(Me.txtASMNo) Then
    MsgBox "Please enter both numbers!", vbExclamation
    ' And get out
    Exit Sub
    End If
    End If
    DoCmd.OpenReport stDocName, acPreview
    Exit_cmdrunreport_Click:
    Exit Sub

    Err_cmdrunreport_Click:
    MsgBox Err.Description
    Resume Exit_cmdrunreport_Click

    End Sub
    If someone doesn't fill in one or the other top two text boxes - I don't want the report to run
    and like wise for the bottom two text boxes.

    The code above doesn't work. They get the error message but the report runs.
    The form works if the person enters it correctly - but I know someone is going to enter just one of the numbers without the other and have access to the report. They need to have both numbers. Client mgrs need their numbers and ASMs need their numbers.

  2. #2
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Problem with report code (2003)

    The way your code is written, the report will always run if the first conditions are met and you still "scold" the user. Your code delivers the message to enter both numbers and then exits the if then loop and then sees the code to run the report. You just need to add another exit sub line below the Message Box to enter both numbers.

    MsgBox "Please enter both Numbers!", vbExclamation
    Exit Sub ' Add This
    Else
    Regards,

    Gary
    (It's been a while!)

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem with report code (2003)

    A couple of suggestions you could try.
    1. Add an option group with two buttons - Client Mgr and ASM - to the form and using the On Load event, hide all the controls except the option group.
    When the user clicks one of the option group, unhide the two controls appropriate to the option clicked. When the user starts typing in the second control of the pair, unhide a control button to preview the report.
    2. Have all the form controls on view but have the second control of each pair (employee number) locked. When the user types in one of the first controls (Client Mgr or ASM) , hide both the controls belonging to the other option, unlock the employee number field belonging to the first control typed in and make a report preview control button visible.

    Check the contents of the fields in the contol button code.

    Also, have a get out/reset command button always on view in case the user wants to change their mind.
    Any use?
    Silverback
    Silverback

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

    Re: Problem with report code (2003)

    Or try this

    If IsNull(Me.txtEmpid) Or IsNull(Me.txtRepNo) Then
    ' Scold the user
    MsgBox "Please enter both Numbers!", vbExclamation
    ' And get out
    Exit Sub
    End If

    If IsNull(Me.txtEmpID2) Or IsNull(Me.txtASMNo) Then
    ' Scold the user
    MsgBox "Please enter both numbers!", vbExclamation
    ' And get out
    Exit Sub
    End If

Posting Permissions

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