• Required field (Access 2000)

    Author
    Topic
    #390161

    I have a form that has a button which creates a report from fields on the form

    Is it possible to say if a specific text box is empty, an error will come up and the report will not be generated. Then when they click ok, fill in that field, then they can make a report

    Viewing 0 reply threads
    Author
    Replies
    • #691996

      In your button’s Click event, you merely need something like this:

      If isnull(txtCertainField) then
      msgbox “Hey, you need to fill in this Certain Field!”,vbexclamation
      exit sub
      end if
      docmd.openreport ……..etc…….

      • #691999

        Just prior to the exit sub I would add

            txtCertainField.SetFocus

        to take the user to the incomplete field.

        • #692000

          The First Part worked Great Thanks Mark

          The Setfocus did not work, could it be because the button is in the footer and the text field is in the header??

          • #692003

            Also, Is there a way I can code it to open up the report or tell it to run a specific macro after this, i guess macro would be easier

            • #692024

              Can you rephrase that? I don’t understand what you want to happen.

            • #692028

              well first i would like the setfocus command to work, any tips??

              Second I want to run a macro that is in my program in the same event

            • #692030

              Can you post the On Click event procedure of the command button as it stands now? (You don’t have to post the entire form module, just the code for the command button)

        • #692031

          Actually, the way I normally handle it is to make the background red for any fields that are incomplete, then have a single message box that says “Hey, you’ve got incomplete fields”. Moving to ay field sets its backcolor to normal.

          • #692033

            Private Sub Print_Click()
            If IsNull(Text_Notification_Number) Then
            MsgBox “Notification No is a Required Field!”, vbExclamation
            Exit Sub
            Text_Notification_Number.SetFocus
            End If

            End Sub

            • #692038

              At the moment, you exit the procedure before setting focus to the text box, so the SetFocus is not executed.

              Change it as follows:

              Private Sub Print_Click()
              ‘ Check if Text_Notification_Number has been filled in
              If IsNull(Text_Notification_Number) Then
              ‘ Inform user
              MsgBox “Notification No is a Required Field!”, vbExclamation
              ‘ First set focus to empty text box
              Text_Notification_Number.SetFocus
              ‘ and then get out
              Exit Sub
              End If

              ‘ Code to open report goes here, for example
              DoCmd.OpenReport “rptMyReport”, acViewPreview
              ‘ Instead of the above instruction, you can call another procedure here
              ‘ or execute a macro using code like DoCmd.RunMacro “MyMacro”
              End Sub

            • #692040

              that worked quite well, thank you to everyone who helped

            • #692966

              Regarding the subject of required fields; however what if you want to check mutilpe fields and anyone of the fields are Null; I still would want the MsgBox to be displayed. How would you write the If IsNull Statement.

            • #692983

              If you want to check several fields, just use an If IsNull(…) Then statement for each of the variables. Using the example from higher up in this thread:

              Private Sub Print_Click()
              ‘ Check if Text_Notification_Number has been filled in
              If IsNull(Text_Notification_Number) Then
              ‘ Inform user
              MsgBox “Notification No is a Required Field!”, vbExclamation
              ‘ First set focus to empty text box
              Text_Notification_Number.SetFocus
              ‘ and then get out
              Exit Sub
              End If

              ‘ Check if Second_Field has been filled in
              If IsNull(Second_Field) Then
              ‘ Inform user
              MsgBox “Second_Field is a Required Field!”, vbExclamation
              ‘ First set focus to empty text box
              Second_Field.SetFocus
              ‘ and then get out
              Exit Sub
              End If

              ‘ Check if Another_Field has been filled in
              If IsNull(Another_Field) Then
              ‘ Inform user
              MsgBox “Another_Field is a Required Field!”, vbExclamation
              ‘ First set focus to empty text box
              Another_Field.SetFocus
              ‘ and then get out
              Exit Sub
              End If

              ‘ Code to open report goes here, for example
              DoCmd.OpenReport “rptMyReport”, acViewPreview
              End Sub

            • #693025

              HansV;
              Your the man; it worked like a charm. If fact; I really used the code system to open a subform not a report. I really will need to look at the rest of your posting. Who knows how many nuggets of gold are just laying around for the picking.

              Thanks;
              MigAnt

    Viewing 0 reply threads
    Reply To: Required field (Access 2000)

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

    Your information: