J
J. B.
Hey,
I have a form in my database that I would like to do a SQL query on a table
to determine if the entered data will duplicate an already existing record.
Here is my code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim bWarn As Boolean 'Flag to warn user
Dim strMsg As String 'Message to display to user
Dim strWhere As String 'Where clause for DLookup()
Dim varID As Variant ' Results of DLookup()
If Me.NewRecord Then 'Only for new records
'Warn if these fields are blank
If IsNull(Me.Artist) Then
bWarn = True
strMsg = strMsg & "Artist is blank" & vbCrLf
End If
End If
varID = 0
'if they're not blank, check if the combination exits.
If Not bWarn Then
varID = DLookup("Artist", "Artist", "Artist = '" & [Artist] & "'")
If Not IsNull(varID) Then
bWarn = True
strMsg = strMsg & "Possible duplicate of artist " & varID & "."
End If
'If we set a warning flag, ask the user what to do
If bWarn Then
strMsg = strMsg & vbCrLf & "Continue anyway?"
If MsgBox(strMsg, vbYesNo + vbDefaultButton2, "Warning") _
<> vbYes Then
Cancel = True
End If
End If
End If
I was wondering how would contruct the same query using SQL statement. The
WHERE statement would be dependent on the data that is entered in the Artist
field.
I would also like to know how to use the SQL statement to check on more than
one field in the record. I did it before but I forgot how I did it. My
WHERE statement was defined by the variable stLinkCriteria which was defined
as follows:
stLinkCriteria = "[CustID]=" & Me![CustID] & " AND [OpenClose] =" &
Me![OpenClose]
I was wondering if someone could provide some assistance on formulating the
SQL statement.
Thanks in advance,
J. B.
I have a form in my database that I would like to do a SQL query on a table
to determine if the entered data will duplicate an already existing record.
Here is my code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim bWarn As Boolean 'Flag to warn user
Dim strMsg As String 'Message to display to user
Dim strWhere As String 'Where clause for DLookup()
Dim varID As Variant ' Results of DLookup()
If Me.NewRecord Then 'Only for new records
'Warn if these fields are blank
If IsNull(Me.Artist) Then
bWarn = True
strMsg = strMsg & "Artist is blank" & vbCrLf
End If
End If
varID = 0
'if they're not blank, check if the combination exits.
If Not bWarn Then
varID = DLookup("Artist", "Artist", "Artist = '" & [Artist] & "'")
If Not IsNull(varID) Then
bWarn = True
strMsg = strMsg & "Possible duplicate of artist " & varID & "."
End If
'If we set a warning flag, ask the user what to do
If bWarn Then
strMsg = strMsg & vbCrLf & "Continue anyway?"
If MsgBox(strMsg, vbYesNo + vbDefaultButton2, "Warning") _
<> vbYes Then
Cancel = True
End If
End If
End If
I was wondering how would contruct the same query using SQL statement. The
WHERE statement would be dependent on the data that is entered in the Artist
field.
I would also like to know how to use the SQL statement to check on more than
one field in the record. I did it before but I forgot how I did it. My
WHERE statement was defined by the variable stLinkCriteria which was defined
as follows:
stLinkCriteria = "[CustID]=" & Me![CustID] & " AND [OpenClose] =" &
Me![OpenClose]
I was wondering if someone could provide some assistance on formulating the
SQL statement.
Thanks in advance,
J. B.