Results 1 to 13 of 13
  1. #1
    edwardcga is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    31

    require input in a field when condition met

    I want to make the field in the subform for donations if payment by CHQ or VISA to require user to input chq # or VISA ref. no. How can I accomplish this. I have 2 tables, Main and detail. Detail have a column call RefNo for chq # or Visa reference. If payment by cash, no need to input no (and automatically forward to next field) otherwise prompt user to input the data before forwarding to next field. Is this possible.



    Thanks for all the advise and support.

    EW

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    This check would need to be in the BeforeUpdate event of the SubForm with Cancel set True until you are satisfied with the input.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    How are you documenting whether a payment is made by cash, check or Visa?

    Linq ;0)>

  4. #4
    edwardcga is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    31

    Validation rule

    Quote Originally Posted by Missinglinq View Post
    How are you documenting whether a payment is made by cash, check or Visa?

    Linq ;0)>
    Offering envelopes either in cash, cheques or VISA slip. So when entering detail in subform, the user will select the type of payment accordingly in the column "PAYT_TYPE", tab to the next field "PAYT_REF" and enter the reference. I would like to build a validation rule that if paid by cheque or VISA, the user have to input the reference. I would like to know the syntax.

    Thanks

    EW

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    If Me.PAYT_TYPE = "CHQ" And Nz(Me.[chq #], "") = "" Then
       MsgBox "Check Number Must Be Entered!!!"
       [chq #].SetFocus
       Cancel = True
       Exit Sub
    End If
    
    If Me.PAYT_TYPE = "VISA" And Nz(Me.[VISA Ref no], "") = "" Then
       MsgBox "VISA Reference Number Must Be Entered!!!"
       [VISA Ref no].SetFocus
       Cancel = True
       Exit Sub
    End If
    
    End Sub


    Note that you'll need to make sure that all Control names are spelled correctly. Also note that the Square Brackets are only needed around Control names if they contain spaces or non-Alpha/Numeric characters with the exception of the underline character. You really need to stick to Alpha/Numeric characters and the underline character.

    Linq ;0)>

  6. #6
    edwardcga is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    31
    Quote Originally Posted by Missinglinq View Post
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    If Me.PAYT_TYPE = "CHQ" And Nz(Me.[chq #], "") = "" Then
       MsgBox "Check Number Must Be Entered!!!"
       [chq #].SetFocus
       Cancel = True
       Exit Sub
    End If
    
    If Me.PAYT_TYPE = "VISA" And Nz(Me.[VISA Ref no], "") = "" Then
       MsgBox "VISA Reference Number Must Be Entered!!!"
       [VISA Ref no].SetFocus
       Cancel = True
       Exit Sub
    End If
    
    End Sub


    Note that you'll need to make sure that all Control names are spelled correctly. Also note that the Square Brackets are only needed around Control names if they contain spaces or non-Alpha/Numeric characters with the exception of the underline character. You really need to stick to Alpha/Numeric characters and the underline character.

    Linq ;0)>
    Thank you for your help. I will try with the code above.

    EW

  7. #7
    edwardcga is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    31
    [QUOTE=edwardcga;195912]Thank you for your help. I will try with the code above.

    I tried the code it came out with runtime error 2108.

    EW

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    What event do you have the code placed in? It has to be in the Form_Update event; it sounds as if you've placed it in the Update event of one of the Textboxes, going by the error you've encountered.

    Linq ;0)>

  9. #9
    edwardcga is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    31
    Quote Originally Posted by Missinglinq View Post
    What event do you have the code placed in? It has to be in the Form_Update event; it sounds as if you've placed it in the Update event of one of the Textboxes, going by the error you've encountered.

    Linq ;0)>
    I have the code in BeforeUpdate Event.

    EW

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    In which BeforeUpdate event? The Form, itself, has a BeforeUpdate event, which is where the code needs to be, and each Textbox, Combobox, Checkbox, etc. has a BeforeUpdate event.

    Placing the code anywhere other than in the Form_BeforeUpdate will result in the error you've encountered.

    Linq ;0)>

  11. #11
    edwardcga is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    31
    Quote Originally Posted by Missinglinq View Post
    In which BeforeUpdate event? The Form, itself, has a BeforeUpdate event, which is where the code needs to be, and each Textbox, Combobox, Checkbox, etc. has a BeforeUpdate event.

    Placing the code anywhere other than in the Form_BeforeUpdate will result in the error you've encountered.

    Linq ;0)>
    I pasted it in the form BeforeUpdate under the field CHQ_NO (Where I would like to input the chq# or VISA ref no.). The following code:

    Private Sub CHQ_NO_BeforeUpdate(Cancel As Integer)

    If Me.PAYT_TYPE = "CHQ" And Nz(Me.[CHQ_NO], "") = "" Then
    MsgBox "Check Number Must Be Entered!!!"
    [CHQ_NO].SetFocus
    Exit Sub
    End If

    If Me.PAYT_TYPE = "VISA" And Nz(Me.[CHQ_NO], "") = "" Then
    MsgBox "VISA Reference Number Must Be Entered!!!"
    [CHQ_NO].SetFocus
    Exit Sub
    End If

    End Sub

    My data entries are in sub form datasheet format tab across the row. When I select payt_type (chq or visa) and press return to the field CHQ_NO, I press return to go to the next field, it did not stop and bring up the message. I click back to the field CHQ_NO enter the ref and take it out, the message brought up
    "Check Number Must Be Entered!!!"


    I click OK AND the next screen come up SHOWS the run-time error message 2108

    I click Debug it jump to the VBA and highlighted the [CHQ_NO].SetFocus

    Please advise how to resolve the issue.

    Thanks

    EW

  12. #12
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by edwardcga View Post

    ...Please advise how to resolve the issue...
    I have 'advised' you how to solve the problem three times, including the code example I gave you! Put the code in the Form_BeforeUpdate event! Do not put it anywhere else!

    When doing validation, like this, that involves two or more Controls, the code belongs in the Form_BeforeUpdate event. Validation is then done just prior to the Record being saved, when the user has completed data entry.

    Linq ;0)>

  13. #13
    edwardcga is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    31

    Red face

    Quote Originally Posted by Missinglinq View Post
    I have 'advised' you how to solve the problem three times, including the code example I gave you! Put the code in the Form_BeforeUpdate event! Do not put it anywhere else!

    When doing validation, like this, that involves two or more Controls, the code belongs in the Form_BeforeUpdate event. Validation is then done just prior to the Record being saved, when the user has completed data entry.

    Linq ;0)>
    Thanks for your patience. I finally get it done. I have typo which causing the problem. The validation came when the input finish and jump back to the field for input. Thanks again.

    EW

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

Similar Threads

  1. Input Mask to Require First and Last names
    By justair07 in forum Access
    Replies: 4
    Last Post: 08-20-2013, 06:11 AM
  2. Replies: 7
    Last Post: 10-24-2012, 05:22 PM
  3. DLookup with multiple field condition
    By agent- in forum Programming
    Replies: 4
    Last Post: 10-15-2011, 05:17 PM
  4. Replies: 6
    Last Post: 05-05-2011, 08:50 AM
  5. Replies: 1
    Last Post: 09-13-2010, 01:57 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