• Dialog Box

    Author
    Topic
    #355051

    Good Morning,

    I have a Parameter Query that is the recordsource for fProjInfo. When the user opens fProjInfo a Dialog box appears requesting the user to input a Project Number. Fine!!

    Now if the user wants to make another search, (this is the only way I knew how to do it…I’m sure there is something better….but) I put a control button on the form with the following code in the OnClick event:

    Function mQ12()
    On Error GoTo mQ12_Err

    DoCmd.Close acForm, “fProjInfo”
    DoCmd.OpenForm “fProjInfo”, acNormal, “”, “”, , acNormal
    mQ12_Exit:
    Exit Function

    mQ12_Err:
    MsgBox Error$
    Resume mQ12_Exit

    End Function

    Fine!!!! Until the user inputs a number that doesn’t exist…it only returns a blank form and the only thing that the user can do is Close the DB and re-open.

    If the user inputs a number that doesn’t exist, I would like a dialog box to appear and notify the user “no such number, please re-enter a project code” and then run the query again. What do I need to do to accomplish this?

    Thanks in advance,

    Viewing 1 reply thread
    Author
    Replies
    • #523001

      in one of my databases i have a separate form to key in the numbers then a second form shows the data i use this code to stop the blank screen you talked about

      Private Sub Form_Open(Cancel As Integer)
      Dim rst As DAO.Recordset
      On Error GoTo err
      Set rst = Me.RecordsetClone
      With rst
      rst.FindFirst “FORMS![OPENING FORM]![TEXTbox]'” = Me![data form textbox] & “‘”

      If .NoMatch Then

      DoCmd.Close acForm, “OPENING FORM”
      GoTo something
      Else

      End If
      End With
      Set rst = Nothing
      DoCmd.Close acForm, “OPENING FORM”

      err:
      DoCmd.Close acForm, “data form”
      MsgBox “There is no such record”
      something:
      DoCmd.Close acForm, “OPENING FORM”
      End Sub
      HTH

      • #523089

        Good Morning Jerry,

        Thanks for your reply….I know this is what I am looking for but I have a small problem and was hoping you could help me.

        I put the following code in the OnOpen event of fHello form (your opening form):

        Private Sub Form_Open(Cancel As Integer)
        Dim rst As DAO.Recordset
        On Error GoTo Err
        Set rst = Me.RecordsetClone
        With rst
        rst.FindFirst “Forms![fHello]![ProjNum]'” = Me![Project_Nbr] & “‘”
        rst.FindFirst “Forms![fHello]![Task]'” = Me![Task_Code] & “‘”

        If .NoMatch Then
        DoCmd.Close acForm, “fHello”
        GoTo something
        Else

        End If
        End With
        Set rst = Nothing
        DoCmd.Close acForm, “fHello”
        Err:
        DoCmd.Close acForm, “fLaborCost”
        MsgBox “Incorrect Project Number – Please re-enter”
        something:
        DoCmd.Close acForm, “fHello”
        ‘End Sub

        fHello has to text boxes, 1)Project Code and 2) Task No. in AfterUpdate event of Task No. I put this line of code:

        DoCmd.OpenForm “fLaborCost”, acNormal, “”, “”, , acNormal

        fLaborCost is the form that holds cost involved on each project. (your data form)

        When I open fHello, the dialog box comes up informing me that I have entered a wrong project no. I don’t have the opportunity to input data in the 2 text boxes. Any idea why?

        I know once I get past this it will do exactly as you said it would, but I am stumped.

        Please help!

        Thanks,

        • #523104

          try placing in the on open of the “fLaborCost” form
          not the hello form
          HTH

    • #523107

      Hi Roberta –

      How about minimizing the chance for user error? Instead of letting her mistype a number, give her a lookup from which she can select a project (from a combobox, say).

    Viewing 1 reply thread
    Reply To: Dialog Box

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: