Results 1 to 3 of 3
  1. #1
    ismith is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    39

    Need Help!!

    Hello,

    Im creating a form in Access 2010.
    Ive made some text boxes and 1 combo box.
    Im trying to validate them using If statement. If i do them all in seperate If statements it works but I want them to validate in 1 if statement.

    If there any way its possible?

    This is what im trying.

    If Not IsNumeric(Me.txtQuantity) Then
    MsgBox "Quantity can only contain numbers!", vbCritical, "Quantity"

    Else If txtDescription.Text = "" Or cbCategory.Text = "" Or txtSize.Text = "" Or txtQuantity.Text = "" Or txtPrice.Text = "" Then


    err = err + 1
    MsgBox "Please fill in all the Fields!"
    End If
    Else
    End If


    'err' is an error Int which im using to track the error and then using that to see if everything is validated to enter into database.
    Thats the code. Its giving me an error saying 2nd statement should be on Line 1. But when i change it round it gives the same error.

    Btw cbCategory stands for Combo box.


    Can any1 help????

    Thanks in advance..

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    What is giving you the error?

    Quote Originally Posted by ismith View Post
    Hello,

    Im creating a form in Access 2010.
    Ive made some text boxes and 1 combo box.
    Im trying to validate them using If statement. If i do them all in seperate If statements it works but I want them to validate in 1 if statement.

    If there any way its possible?

    This is what im trying.

    If Not IsNumeric(Me.txtQuantity) Then
    MsgBox "Quantity can only contain numbers!", vbCritical, "Quantity"

    Else If txtDescription.Text = "" Or cbCategory.Text = "" Or txtSize.Text = "" Or txtQuantity.Text = "" Or txtPrice.Text = "" Then
    err = err + 1
    MsgBox "Please fill in all the Fields!"
    End If
    Else ????????????????
    End If


    'err' is an error Int which im using to track the error and then using that to see if everything is validated to enter into database.
    Thats the code. Its giving me an error saying 2nd statement should be on Line 1. But when i change it round it gives the same error.

    Btw cbCategory stands for Combo box.


    Can any1 help????

    Thanks in advance..
    Are you using the "default", "required" or any of the checking properties?

  3. #3
    ismith is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    39
    I dont think so. Ive only changed the cb so the values cant be edited. Thats all ive done really.

    When i do the code like below it works:

    txtDescription.SetFocus
    If txtDescription.Text = "" Then
    err = err + 1
    MsgBox "Please fill in the Description box!"
    End If

    cbCategory.SetFocus
    If cbCategory.Text = "" Then
    err = err + 1
    MsgBox "Please select a Category!"
    End If

    txtSize.SetFocus
    If txtSize.Text = "" Then
    err = err + 1
    MsgBox "Please fill in the Size box!"
    End If

    txtQuantity.SetFocus
    If txtQuantity.Text = "" Then
    err = err + 1
    MsgBox "Please fill in Quantity box!"
    End If

    If Not IsNumeric(Me.txtQuantity) Then
    err = err + 1
    MsgBox "Quantity can only contain numbers!", vbCritical, "Quantity"
    End If

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

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