N
niuginikiwi
I have a main form and a subform.
On the maind form I have a combo called CustomerID and and text field called
OrderDate.
All I want to do is check to see if a record with the combination of
Customer and Order Date already exists and if it does, undo the insert or
edit and if it doesn't accept the insert or edit.
I have the code below that does the check but still tells em that there is a
duplicate even though I verified and know that there is no same record as the
new one that I'm just about to enter. Can anyone look at the code and tell me
where I am going wrong?
Here is the code that I gethered through this forum and is on before update
event of the main form.
Dim strWhere As String
Dim varResult As Variant
Dim strMsg1 As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
If (Me.CustomerID = Me.CustomerID.OldValue) And _
(Me.OrderDate = Me.OrderDate.OldValue) Then
'do nothing
Else
strWhere = "(CustomerName = """ & Me.CustomerID.Column(1) & """) AND
(OrderDate = " _
& Format(Me.OrderDate, conDateFormat) & ")"
varResult = DLookup("OrderID", "tblOrders", strWhere)
If Not IsNull(varResult) Then
strMsg1 = "You already have on record" & vbCrLf &
Me.CustomerName & vbCrLf & "for " & Me.OrderDate & " on " & Format(varResult,
"\E00000") & _
vbCrLf & "CONTINUE ANYWAY?"
If MsgBox(strMsg1, vbYesNo + vbDefaultButton2, "Duplicate
Record") <> vbYes Then
Cancel = True
End If
End If
End If
On the maind form I have a combo called CustomerID and and text field called
OrderDate.
All I want to do is check to see if a record with the combination of
Customer and Order Date already exists and if it does, undo the insert or
edit and if it doesn't accept the insert or edit.
I have the code below that does the check but still tells em that there is a
duplicate even though I verified and know that there is no same record as the
new one that I'm just about to enter. Can anyone look at the code and tell me
where I am going wrong?
Here is the code that I gethered through this forum and is on before update
event of the main form.
Dim strWhere As String
Dim varResult As Variant
Dim strMsg1 As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
If (Me.CustomerID = Me.CustomerID.OldValue) And _
(Me.OrderDate = Me.OrderDate.OldValue) Then
'do nothing
Else
strWhere = "(CustomerName = """ & Me.CustomerID.Column(1) & """) AND
(OrderDate = " _
& Format(Me.OrderDate, conDateFormat) & ")"
varResult = DLookup("OrderID", "tblOrders", strWhere)
If Not IsNull(varResult) Then
strMsg1 = "You already have on record" & vbCrLf &
Me.CustomerName & vbCrLf & "for " & Me.OrderDate & " on " & Format(varResult,
"\E00000") & _
vbCrLf & "CONTINUE ANYWAY?"
If MsgBox(strMsg1, vbYesNo + vbDefaultButton2, "Duplicate
Record") <> vbYes Then
Cancel = True
End If
End If
End If