I've got two forms, one is for list of users "frmMembers" and another to get new users via outlook application code "frmNewMember".
Once I click on "OK" button "cmdOk" it runs the following code:
My problem is that this creates two records in my "tblMember". One which is expected with all information, and another record with empty fields EXCEPT for E-Mail address.
I cannot isolate this issue. Can someone figure it out?
Edit: If it helps, it seams it makes bad record first, then the good one, in that order.
Once I click on "OK" button "cmdOk" it runs the following 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 & "') "
' Exit the form
DoCmd.Close acForm, Me.Name
' 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
My problem is that this creates two records in my "tblMember". One which is expected with all information, and another record with empty fields EXCEPT for E-Mail address.
I cannot isolate this issue. Can someone figure it out?
Edit: If it helps, it seams it makes bad record first, then the good one, in that order.