Need help with this code

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

Thanks for reading this post.

What I'm trying to do is to create a "Find" box. I have some code that I
picked up and it works great by its self. The problem is that I'm trying to
use it as a subform on the main form. What the program does is after you
enter the persons last name the program will go and find it. Like I said it
works by its self. As a subform all it does is say that there was no match.
What I'm also trying to do is when the last name is found on the subform then
I want the main form to coincide with the sub.

Here is the code.

Private Sub txtSearch_AfterUpdate()
Dim lNameRef, stwhere, strSearch, strWhere As String

'Check txtSearch for Null value or Nill Entry first.

10 If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
20 MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!
"
30 Me![txtSearch].SetFocus
40 Exit Sub
50 End If
'---------------------------------------------------------------

'Performs the search using value entered into txtSearch
'and evaluates this against values in lName
'DoCmd.ShowAllRecords
'txtSearch.Visible = False
'LName.Visible = True


60 DoCmd.GoToControl ("lname")
70 DoCmd.FindRecord txtSearch

80 LName.SetFocus
90 lNameRef = LName.Text
100 txtSearch.SetFocus
110 strSearch = txtSearch.Text

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

120 If lNameRef = strSearch Then
MsgBox "Match Found For: " & strSearch, , "Congratulations!"
130 LName.SetFocus
140 txtSearch = ""

'If value not found sets focus back to txtSearch and shows msgbox
150 Else
160 Call MsgBox("Match Not Found For: " & strSearch _
& vbCrLf & "" _
& vbCrLf & "Please Try Again.." _
, vbExclamation, Application.Name)

170 txtSearch = ""
180 txtSearch.SetFocus
190 End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Search form help 3
Working with Filters 0
Search Button 2
Help with search code 4
Optional Search 0
Seaching using text box 6
Type Down Function 2
Enter new record if search returns no results? 17

Top