When I click on OK button, it's supposed to add a record in my table based on the text boxes typed.
It works, but it makes two entries instead of just one.
Here's the code:
It works, but it makes two entries instead of just one.
Here's the code:
Code:
Private Sub cmdOk_Click()
Dim Fail As Boolean: Fail = False
' Check to ensure the pertinate data has been intput
If Not Len(txtLast.Value) > 0 Then
txtLast.BackColor = RGB(255, 0, 0)
Fail = True
Else
txtLast.BackThemeColorIndex = 1
End If
If Not Len(txtFirst.Value) > 0 Then
txtFirst.BackColor = RGB(255, 0, 0)
Fail = True
Else
txtFirst.BackThemeColorIndex = 1
End If
If Not Len(lstTrade.Value) > 0 Then
lstTrade.BackColor = RGB(255, 0, 0)
Fail = True
Else
lstTrade.BackThemeColorIndex = 1
End If
If Not Len(txtEmail.Value) > 0 Then
txtEmail.BackColor = RGB(255, 0, 0)
Fail = True
Else
txtEmail.BackThemeColorIndex = 1
End If
If Fail Then
With CreateObject("WScript.Shell")
Select Case .PopUp("Please fill in all the data in the red boxes before hitting Ok!", 2, "Information", 48)
Case 1, -1
Exit Sub
End Select
End With
End If
On Error GoTo ErrorHandler
' Add the entry
CurrentDb.Execute "INSERT INTO tblMember (fldLastName,fldFirstName,fldEmail,fldTradeID) VALUES('" & txtLast.Value & "','" & txtFirst.Value & "','" & txtEmail.Value & "','" & lstTrade.Value & "') ", dbFailOnError
' Exit the form
DoCmd.Close acForm, Me.Name, acSaveYes
' Update
Forms!frmMembers.DoRequery
Exit Sub
ErrorHandler:
If Err.Number <> 2046 Then
MsgBox Err.Description, vbOKOnly, "Error #: " & Err.Number
Exit Sub
End If
End Sub