• 0

HELP ME: Problem with Access 2007 and vb


Question

im working on a project in access and i want to create a search button. i found a ready code but when im running the search button im getting this error messase

This error occurs when an event has failed to run because Microsoft Office Access cannot evaluate the location of the logic for the event. For example, if the OnOpen property of a form is set to =[Field], this error occurs because Access expects a macro or event name to run when the event is fired.

does any one knows why? here the search code . name of the label is txtSearch and the name of the button is cmdSearch

Option Compare Database

Private Sub cmdSearch_Click()
    Dim struserRef As String
    Dim strSearch As String

'Check txtSearch for Null value or Nill Entry first.

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
        MsgBox "Parakalo isagete timi!", 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 struserID

    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("user_id")
    DoCmd.FindRecord Me!txtSearch

    arithos_tautotitas.SetFocus
    struserRef = auser_id.Text
    txtSearch.SetFocus
    strSearch = txtSearch.Text

'If matching record found sets focus in struserID and shows msgbox
'and clears search control

    If struserRef = strSearch Then
        MsgBox "Match Found For: " & strSearch, , "Congratulations!"
        user_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

thank u

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.