J
James Grady via AccessMonster.com
HI,
This is my first message to post out here on the site. But i have been an
avid user of the site. It has been very helpful in the past. However i
have ran into a problem i cannot get past and i am sure it will be really
easy to fix. I have a form that has 5 textboxes, and when all the
textboxes have been filled, the user clicks a button, and the button
executes and "Insert into" statement that puts the values in the table. So
now i am trying to do some error handling. I want a MSGbox to pop up if
one of the fields hasn't been entered or is left blank (cuz all the fields
need to be entered), and also...to not execute the sql statement.
Currently, when i leave one of the fields blank and then click the button,
the message box comes up sayin "Some field must be entered", but it also
executes the SQL statement, adding the record to the table. How do i go
about this? Do i create a Iif statement or what? here is my code for the
form:
Private Sub btnaddemp_Click()
Dim strSQL As String
If Nz(txtFullname, "") = "" Then
MsgBox "Need Employee Please"
Cancel = True
Me.txtFullname.SetFocus
End If
strSQL = "INSERT INTO Employee (FullName, Address, Phone, Email)
VALUES('" & Me!txtFullname & "', '" & Me!txtAddress & "', '" & Me!txtPhone
& "', '" & Me!txtEmail & "')"
'Using DAO
CurrentDb.Execute strSQL
MsgBox "Customer has been added!"
'Reset form for next new record ...
'Me!txtFullname = Null
'Me!txtAddress = Null
'Me!txtPhone = Null
'Me!txtEmail = Null
End Sub
This is my first message to post out here on the site. But i have been an
avid user of the site. It has been very helpful in the past. However i
have ran into a problem i cannot get past and i am sure it will be really
easy to fix. I have a form that has 5 textboxes, and when all the
textboxes have been filled, the user clicks a button, and the button
executes and "Insert into" statement that puts the values in the table. So
now i am trying to do some error handling. I want a MSGbox to pop up if
one of the fields hasn't been entered or is left blank (cuz all the fields
need to be entered), and also...to not execute the sql statement.
Currently, when i leave one of the fields blank and then click the button,
the message box comes up sayin "Some field must be entered", but it also
executes the SQL statement, adding the record to the table. How do i go
about this? Do i create a Iif statement or what? here is my code for the
form:
Private Sub btnaddemp_Click()
Dim strSQL As String
If Nz(txtFullname, "") = "" Then
MsgBox "Need Employee Please"
Cancel = True
Me.txtFullname.SetFocus
End If
strSQL = "INSERT INTO Employee (FullName, Address, Phone, Email)
VALUES('" & Me!txtFullname & "', '" & Me!txtAddress & "', '" & Me!txtPhone
& "', '" & Me!txtEmail & "')"
'Using DAO
CurrentDb.Execute strSQL
MsgBox "Customer has been added!"
'Reset form for next new record ...
'Me!txtFullname = Null
'Me!txtAddress = Null
'Me!txtPhone = Null
'Me!txtEmail = Null
End Sub