Results 1 to 13 of 13
  1. #1
    Join Date
    Apr 2004
    Location
    ny, ny
    Posts
    224

    Unanswered: field validation

    I have a few fields in a form along with a close button, save, print and so on. I need to be able to not allow the user to save or close or print until data is entered in the fields
    So if field 1 and field 2 are not entered and the user tries to save, a msg box should pop up stating that field 1 and field 2 have not been entered

    thank you

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: field validation

    Originally posted by fullymooned
    I have a few fields in a form along with a close button, save, print and so on. I need to be able to not allow the user to save or close or print until data is entered in the fields
    So if field 1 and field 2 are not entered and the user tries to save, a msg box should pop up stating that field 1 and field 2 have not been entered

    thank you
    Why don't you do this: Default the buttons to be disabled and then enable them upon data entry ... This is a test of contents in the control's Afte_Update event ..

  3. #3
    Join Date
    Apr 2004
    Location
    ny, ny
    Posts
    224
    no that doesnt seem to work.. I need to write some code for the button so when it gets clicked i can check whether my fields are empty or not and then pop up a msg box

  4. #4
    Join Date
    Apr 2004
    Location
    South Arica
    Posts
    125
    Could you not just check the length of each text box, then display a msg box if the length=0

    if len(trim(text1))=0 then

  5. #5
    Join Date
    Apr 2004
    Location
    South Arica
    Posts
    125
    Could you not just check the length of each text box, then display a msg box if the length=0

    if len(trim(text1))=0 then
    msgbox "Enter message here"
    end if

  6. #6
    Join Date
    Apr 2004
    Location
    ny, ny
    Posts
    224
    its not a text box , its a number

  7. #7
    Join Date
    Apr 2004
    Location
    ny, ny
    Posts
    224
    its not a text box , its a number

  8. #8
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231

    Re: field validation

    Originally posted by fullymooned
    I have a few fields in a form along with a close button, save, print and so on. I need to be able to not allow the user to save or close or print until data is entered in the fields
    So if field 1 and field 2 are not entered and the user tries to save, a msg box should pop up stating that field 1 and field 2 have not been entered

    thank you
    behind your button_click() event, just put something like

    Code:
    Private Sub cmdSave_Click()
    
     If text1 = "" Or text2 = "" Then
        MsgBox "Your Message Here"
        Exit Sub
     Else
        Save
     End If
    
    End Sub

  9. #9
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by fullymooned
    no that doesnt seem to work.. I need to write some code for the button so when it gets clicked i can check whether my fields are empty or not and then pop up a msg box
    And why is that? Case in point: I do that very thing ... But you do as you wish ...

    Private Sub SomeButton_Click()
    dim NotOK As Boolean

    NotOK=false
    if TextBox1.Value & "" ="" then NotOK=True
    if TextBox2.Value & "" ="" then NotOK=True
    if Textbox3.Value & ""="" then NotOK=True
    ...

    If NotOK Then
    MsgBox "You can't do that ..."
    else
    ' Do whatever here ...
    endif
    End Sub

  10. #10
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Originally posted by fullymooned
    its not a text box , its a number
    since it is a number, do as Saila suggested (it is a number in a form field, which is actually a text box formatted as a number field)

    D.

  11. #11
    Join Date
    Apr 2004
    Location
    South Arica
    Posts
    125
    How is the data entered, all the line
    if len(trim(text1)) = 0
    does is check whether or not data is contained in the field. As long as the user has to enter data, this can be used. Just replace text1 with the name of the field.

  12. #12
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Originally posted by kedaniel
    since it is a number, do as Saila suggested (it is a number in a form field, which is actually a text box formatted as a number field)

    D.
    ah, but then you also need to test for Null (nothing, not even zero - 0 )

    if not isnull(me.textboxname)then
    if len(trim(me.textboxname))=0 then

    D.

  13. #13
    Join Date
    Apr 2004
    Location
    ny, ny
    Posts
    224
    works
    thanks guys

Posting Permissions

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