J
Juan Schwartz
I am trying to make a function that will check for dupes based on
certain dynamic criteria. I get an error when running my query with
brackets inserted around what could be table/field names with spaces.
It's treating it like a parameter instead of a table/field name. Any
assistance would be appreciated.
Also, in my function, is there a way to let "dupestring" in the
function slip through as a null value as I have a check for that in
the function...
Function checkdupestring(dupestring As String, dupetable As String,
dupefield As String, fieldname As String)
If Len(dupestring) > 0 Then
Dim dupe As Recordset
If dupe.RecordCount > 0 Then
MsgBox ("Duplicate record found in database with " &
fieldname & ": " & dupestring & ".")
End
End If
End If
End Function
certain dynamic criteria. I get an error when running my query with
brackets inserted around what could be table/field names with spaces.
It's treating it like a parameter instead of a table/field name. Any
assistance would be appreciated.
Also, in my function, is there a way to let "dupestring" in the
function slip through as a null value as I have a check for that in
the function...
Function checkdupestring(dupestring As String, dupetable As String,
dupefield As String, fieldname As String)
If Len(dupestring) > 0 Then
Dim dupe As Recordset
Debug.Printdupetable = "[" & dupetable & "]" 'When this line and the line below are commented out, it works... unless the field/table/whatever has a space in it which would require the brackets.
dupefield = "[" & dupefield & "]"
Set dupe = CurrentDb.OpenRecordset("SELECT * FROM " & dupetable & " WHERE " & dupefield & " = '" & dupestring & "'") 'This is the actual error line
If dupe.RecordCount > 0 Then
MsgBox ("Duplicate record found in database with " &
fieldname & ": " & dupestring & ".")
End
End If
End If
End Function