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
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