"Access could not recognize"

Chrisopia

Registered User.
Local time
Today, 04:28
Joined
Jul 18, 2008
Messages
279
The code below is for a search tool, but it returns an error if there isn't any data in the CompanyName field. To get around this I want to divert it to the LastName if there isnt anything in CompanyName.


I thought I could create a variable (CompLast) to use instead of using either CompanyName or LastName in the search tool.
Obviously this wasn't the way to go... what can I do?

Code:
Private Sub QuickSearch_AfterUpdate()
    
    Dim CompLast As String
    CompLast = [CompanyName]
    If IsNull(Me![CompanyName]) Then
    CompLast = Me![LastName]
    End If
    
DoCmd.Requery
Me.RecordsetClone.FindFirst "CompLast = '" & Me![QuickSearch] & "'"
If Not Me.RecordsetClone.NoMatch Then
   Me.Bookmark = Me.RecordsetClone.Bookmark
Else
   MsgBox "Could not locate [" & Me![QuickSearch] & "]"
End If
End Sub
 
You may want to consider adding another layer or two to the process; it may make things slightly more manageable...

Very rough...just to get you thinking along these lines...

Code:
Private Sub QuickSearch_AfterUpdate()

    If Len(Me.CompanyName) Then
      SearchByCompanyName(Me.CompanyName)
    Else
      SearchByLastName(Me![LastName])
    End If
    
End Sub


Sub SearchByCompanyName(companyName as string)

  Me.RecordsetClone.FindFirst "CompanyName = '" & companyName & "'"
  If Not Me.RecordsetClone.NoMatch Then
    Me.Bookmark = Me.RecordsetClone.Bookmark
  Else
    MsgBox "Could not locate " & companyName
  End If

End Sub

Sub SearchByLastName(lastName as string)

  Etc.

End Sub

Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom