Katana24
Katana24

Reputation: 8959

Operation not supported in search criteria

Im trying to create a simple search function in VB. It's constructed as follows:

Dim rst As recordSet
Dim lastName As String
Dim firstName As String
Dim eventTitle As String

'Current Record set
Set rst = CurrentDb.OpenRecordset("tblWebMeetingData")

If (IsNull(Me.txtFldLastName) = False) Then
    lastName = Me.txtFldLastName
    rst.FindFirst "[Last Name] = " & lastName
    MsgBox ("Found record")
Else
    MsgBox ("Record not found")
End If

If (IsNull(Me.txtFldFirstName) = False) Then
    firstName = Me.txtFldFirstName
End If

If (IsNull(Me.txtFldEventTitle) = False) Then
    eventTitle = Me.txtFldEventTitle
End If

But I keep getting an error of "Operation is not supported for this type of object." What gives? The Last Name field is spaced in the table

Upvotes: 0

Views: 129

Answers (2)

Katana24
Katana24

Reputation: 8959

the reason why i was getting an error was because I was trying to use the Find First method against a table object and not a Dynaset or Snapshot object. To fix this I replaced the parameter in the .OpenRecordSet with a SQL statement that takes in what it is I want to search for.

Thanks for your help Hans Up as what you said needed to be in in order to work.

Upvotes: 1

HansUp
HansUp

Reputation: 97101

If this is the line which throws the error ...

rst.FindFirst "[Last Name] = " & lastName

[Last Name] is likely text data type, so use quotes in the .FindFirst string.

rst.FindFirst "[Last Name] = '" & lastName & "'"

If the last names may contain apostrophes, double them up.

rst.FindFirst "[Last Name] = '" & Replace(lastName, "'", "''") & "'"

Upvotes: 2

Related Questions