Same stupid error message...search command

ArcherSteve

Perpetually Confused
Local time
Yesterday, 19:09
Joined
Jan 10, 2004
Messages
48
Here's the code...

Code:
Private Sub Command53_Click()
    Dim strArcherRef As String
    Dim strSearch As String
    
'Check txtSearch for Null value or Nill Entry first.

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
        MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
        Me![txtSearch].SetFocus
    Exit Sub
End If
'---------------------------------------------------------------
        
'Performs the search using value entered into txtSearch
'and evaluates this against values in ID
        
    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("First")
    DoCmd.FindRecord Me!txtSearch
        
    First.SetFocus
    strArcherRef = ID.Text
    txtSearch.SetFocus
    strSearch = txtSearch.Text
        
'If matching record found sets focus in ID and shows msgbox
'and clears search control

    If strArcherRef = strSearch Then
        ID.SetFocus
        txtSearch = ""
        
    'If value not found sets focus back to txtSearch and shows msgbox
        Else
            MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
            , "Invalid Search Criterion!"
            txtSearch.SetFocus
    End If
End Sub

I keep on getting the same error message "Runtime Error '2185': You can't reference a property or method for a control unless the control has focus." on the line of code " strArcherRef = ID.Text". I've spent some good time on this and still can't figure out why. Any ideas?

Thanks,
Steve
 
don't use .text. Use .value (it's default so it can be omitted)

myvar=me.fieldname.value

or

myvar=me.fieldname
 
I fixed that. Now it only finds the record that has the ID # 1 and only 1. Any other number I search for is not found.... any ideas?
 
actually, it only finds the first entry in the table, and only the first entry...
 
anyone have any ideas? or even a better code for this purpose? please?
 
found the problem.....put the wrong field name in....thanks anyways guys
 

Users who are viewing this thread

Back
Top Bottom