Results 1 to 15 of 15
  1. #1
    3 Star Lounger
    Join Date
    Jun 2003
    Posts
    238
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Required field (Access 2000)

    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

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Required field (Access 2000)

    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.......
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Lounger
    Join Date
    May 2002
    Location
    Fort Worth, Texas, USA
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required field (Access 2000)

    Just prior to the exit sub I would add

    <pre> txtCertainField.SetFocus</pre>

    to take the user to the incomplete field.

  4. #4
    3 Star Lounger
    Join Date
    Jun 2003
    Posts
    238
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required field (Access 2000)

    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??

  5. #5
    3 Star Lounger
    Join Date
    Jun 2003
    Posts
    238
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required field (Access 2000)

    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

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

    Re: Required field (Access 2000)

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

  7. #7
    3 Star Lounger
    Join Date
    Jun 2003
    Posts
    238
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required field (Access 2000)

    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

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

    Re: Required field (Access 2000)

    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)

  9. #9
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Required field (Access 2000)

    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.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  10. #10
    3 Star Lounger
    Join Date
    Jun 2003
    Posts
    238
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required field (Access 2000)

    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

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

    Re: Required field (Access 2000)

    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

  12. #12
    3 Star Lounger
    Join Date
    Jun 2003
    Posts
    238
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required field (Access 2000)

    that worked quite well, thank you to everyone who helped

  13. #13
    2 Star Lounger
    Join Date
    Jul 2003
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required field (Access 2000)

    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.

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

    Re: Required field (Access 2000)

    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

  15. #15
    2 Star Lounger
    Join Date
    Jul 2003
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required field (Access 2000)

    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

Posting Permissions

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