Hi there.
Im trying to use some if statements to validate my text boxes.
This is what ive got so far.
What it does atm is just looks at the quantity field and just checks to see if it has numbers in, if i put a number in it adds to database with all the fields blank when its not meant to happen..
Can any1 tell me how to solve this please...
Set database = CurrentDb
If txtDescription.Value = "" Then
MsgBox "Please select a Description", vbExclamation, "Cannot Save"
ElseIf cbCategory.Value = "" Then
MsgBox "Please select a Category", vbExclamation, "Cannot Save"
ElseIf txtSize.Value = "" Then
MsgBox "Please enter a Size", vbExclamation, "Cannot Save"
ElseIf txtQuantity.Value = "" Then
MsgBox "Please enter a Quantity", vbExclamation, "Cannot Save"
ElseIf Not IsNumeric(txtQuantity.Value) Then
MsgBox "Quantity can only contain numbers", vbExclamation, "Cannot Save"
ElseIf txtPrice.Value = "" Then
MsgBox "Please enter a Price", vbExclamation, "Cannot Save"
ElseIf MsgBox("Save Product Details?", vbOKCancel + vbQuestion, "Confirmation") = vbOK Then
'get a reference to the record set in the main form
Set addprod = database.OpenRecordset("productQuery")
addprod.AddNew
addprod!Description = txtDescription.Value
addprod!Category = cbCategory.Value
addprod!Size = txtSize.Value
addprod!Quantity = txtQuantity.Value
addprod!Price = "£" + txtPrice.Value
addprod.Update
End If