Results 1 to 12 of 12
  1. #1
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338

    Make more than one fields required on a form

    Hi



    I have done this before and it worked great but for some reason it's not working now.
    Here is the code i'm using on the form before update

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me.[User]) Then
    MsgBox "Please enter User Name!!!"
    Cancel = True
    User.SetFocus
    End If


    If IsNull(Me.[Provider Name]) Then
    MsgBox "Please enter Provider Name!!!"
    Cancel = True
    [Provider Name].SetFocus
    End If


    End Sub

    Here is a copy of the db[ATTACH]10605


    Attached Files Attached Files

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    I have amended your code. See attached db.
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    Thank you very much for your help.

  4. #4
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    Hi Bob

    I try your code on another form and i'm getting Error 2465- Microsoft access cant find the field "I" referred in your expression. Here's the code

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    On Error GoTo Err_Form_BeforeUpdate_Error


    If Nz(Me.[User], 0) = 0 Then
    MsgBox "Please enter User Name!!!"
    Cancel = True
    User.SetFocus
    Exit Sub
    End If


    If Nz(Me.[HSS Number], 0) = 0 Then
    MsgBox "Please enter Hss Number!!!"
    Cancel = True
    [HSS Number].SetFocus
    Exit Sub
    End If


    If Nz(Me.[PatientName], 0) = 0 Then
    MsgBox "Please enter Patient Name!!!"
    Cancel = True
    [PatientName].SetFocus
    Exit Sub
    End If


    If Nz(Me.[PatientLastName], 0) = 0 Then
    MsgBox "Please enter Last Name!!!"
    Cancel = True
    [PatientLastName].SetFocus
    Exit Sub
    End If


    If Nz(Me.[Address], 0) = 0 Then
    MsgBox "Please enter Address!!!"
    Cancel = True
    [Address].SetFocus
    Exit Sub
    End If


    If Nz(Me.[City], 0) = 0 Then
    MsgBox "Please enter City!!!"
    Cancel = True
    [City].SetFocus
    Exit Sub
    End If


    If Nz(Me.[State], 0) = 0 Then
    MsgBox "Please enter state!!!"
    Cancel = True
    [State].SetFocus
    Exit Sub
    End If


    If Nz(Me.[ZipeCode], 0) = 0 Then
    MsgBox "Please enter Zipe Code!!!"
    Cancel = True
    [ZipeCode].SetFocus
    Exit Sub
    End If


    Exit_ErrorHandler:
    Exit Sub


    Err_Form_BeforeUpdate_Error:


    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_BeforeUpdate of VBA Document Form_T_PatientDemographicsForm at Line " & Erl
    Resume Exit_ErrorHandler




    End Sub

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    It would help if we knew which line causes the error.
    You could set a breakpoint and step through the code one line at a time using the F8 key.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    Its at line 0

  7. #7
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    This is what the error says (in procedure Form_BeforeUpdate of VBA Document Form_T_PatientDemographicsForm at Line 0.

  8. #8
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    How can i go about stepping through a code? I try F8 but its not doing any thing. Never done this.

  9. #9
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by Ray67 View Post
    How can i go about stepping through a code? I try F8 but its not doing any thing. Never done this.
    Read this link: http://www.baldyweb.com/Debugging.htm
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  10. #10
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    Bob fitz

    I was able to fix the error that i was getting. I'm just having one more issue on the form. Some of the text box are auto populated based on Hss Number. If the user picks hss number than it displays the patient info name,address,city, state and zipcode. This data is than transfer into payee text box with in the same form. If i was to remove the data from all of the payee text boxes the form save's the records even if they are blank. I don't get any error messages that the code is wrong. The payee fields are set required on the table. I have other text boxes in the form and it works fine with them.
    Example

    HSS Number 111-11-11 OTHER Text box
    Patient name Doe,John Payee Name Doe,John
    Address 123 Street Payee Address 123 Street

  11. #11
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    If the fields are text fields and are their "Allow Zero Length" property is set to "Yes" then this could be why the table level validation doesn't seem to be working.
    You could also write some more code in the form's Before Update event to catch Null and Zero Length Strings for these controls, as you have for others.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  12. #12
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    Bob Fitz

    You are right the fields were set as Yes. I changed the fields to no. It's working now.

    Thank You

Please reply to this thread with any new information or opinions.

Similar Threads

  1. help. too many fields to make a form !!!
    By amd711 in forum Forms
    Replies: 2
    Last Post: 10-23-2012, 08:47 AM
  2. Creating Required Fields on a form
    By topp in forum Access
    Replies: 4
    Last Post: 06-27-2012, 03:20 PM
  3. Resetting a form having "Required" fields
    By hmushtaq in forum Forms
    Replies: 4
    Last Post: 04-19-2011, 08:24 AM
  4. Required Fields in a Form
    By Alaska1 in forum Access
    Replies: 3
    Last Post: 12-23-2010, 01:41 PM
  5. Replies: 1
    Last Post: 09-09-2010, 04:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums