Results 1 to 13 of 13
  1. #1
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239

    Question Table validation - not working


    hiya,

    I have a number of validation rules on my table but violation of any of them gives a text message that lists the WHOLE syntax of the rules. The below table rule works until you violate it. Then after you correct the error, the validation text message wouldn't go away

    IIf([More MgSO4?]="Yes",Not IsNull([extra dosage]),IsNull([extra dosage]))

    I understand that it is better to put the validation rule on the form using VB but I need assistance with the code please. I wrote this code in the AfterUpdate event of [extra dosage] - i.e. the textbox txtExtra but it has bugs. I need assistance with this code please:

    Private Sub txtExtra_AfterUpdate()
    If [More MgSO4?] = "Yes" Then
    If Len([extra dosage].Text & vbNullString) = 0 Then
    MsgBox "Please provide the extra dose!", vbOK + vbExclamation
    Else
    [extra dosage].Text = Me.txtextra.Text
    Len([extra dosage].Text) > 0
    End If
    Else Len([extra dosage].Text) = 0
    End If
    End Sub

  2. #2
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Just to clarify further:

    Basically I have a combo box [More MgSO4?] with values "Yes"; "No"
    If the user selects Yes, then the text box [extra dose] must not be null. The user must provide the dose

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Is [More MgSO4!] bound to a yes/no type field? If so, don't put Yes in quote marks. Actually, use True - not in quote marks.

    The last Else should be two lines.

    BTW, advise no spaces or special characters/punctuation (underscore is exception) in naming convention. The ? mark is not good.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    I would question the need for the yes/no field in the first place. This can be determined by the value of [extra dosage].
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Hi thanks for your responses. No it is not bound to a Yes/No control. It is bound to a combo box which drops down for the user to make a selection. As for the field names, that is why I enclosed them in [] brackets...?

    Also could you advise what two codes those should be...? not clear to me

    many thanks

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    No it is not bound to a Yes/No control. It is bound to a combo box which drops down for the user to make a selection.
    Its value is shown with a combo box but if the value displayed is saved in the underlying table then it is bound to that field.
    As for the field names, that is why I enclosed them in [] brackets...?
    Yes we know only too well why you use them but a name like ExtraDosage is just as easy to read and does not need the use of square brackets. At some point you will forget to use the brackets and this will cause you problems. We see this all too often, so June's advice is worth taking.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Your 'It is bound to a combobox' makes no sense. Is there a field in table for this Yes/No selection in combobox?

    The Yes/No combobox seems extraneous. Why would user click the combobox and not just simply enter the value into [extra dosage]? What assurance is there the user will remember to make the Yes/No selection?

    Yes, the [] force the bad field names to be accepted, but can be a nuisance to have to remember to type them. Follow good naming convention and will be fewer frustrations.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    the field in table and form are combo boxes

  9. #9
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    field names cannot be changed. the user (there is only one) will remember to make a selection otherwise the validation code will remind them. There is a reason for this. all I need is assistance with the code.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Did you try the suggestions in post 3?

    Nothing in the code posted will require user to make selection in the combobox.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Not sure I understand but I think True/False is for when the table field is a Yes/No type isn't it?
    At the table level, data type IS text and the control is a combo box with value list "Yes"; "No

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Okay, I did say "If so".

    Then there is the other suggestion to split a line to two.

    Ooops. Just noticed the code uses .Text. Remove all of those. The property needed is Value and Value is default so don't need to type.

    Why are you setting [Extra Dosage] to txtExtra.Text?

    Also, this expression in both places is meaningless:
    Len([extra dosage].Text) > 0

    Private Sub txtExtra_AfterUpdate()
    If Me.txtExtra = "Yes" Then
    If Me.[extra dosage] & "" = "" Then
    MsgBox "Please provide the extra dose!", vbOK + vbExclamation
    End If
    End If
    End Sub


    Step debug. Review link at bottom of my post for debugging guidelines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    Sheba is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    239
    Many thanks for your help.

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

Similar Threads

  1. Password validation not working
    By nika.duncan in forum Access
    Replies: 4
    Last Post: 11-22-2013, 11:01 AM
  2. Replies: 5
    Last Post: 11-21-2013, 11:42 AM
  3. Validation Rule Not Working??
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 12-23-2011, 02:22 PM
  4. Replies: 2
    Last Post: 10-02-2011, 01:27 PM
  5. Replies: 0
    Last Post: 03-18-2011, 06:38 AM

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