R
ragtopcaddy via AccessMonster.com
Here's my code:
Private Sub txtFindText_AfterUpdate()
Dim strSearch As String
Dim strQuote As String
Dim lngQuoteID As Long
Dim lngAuthID As Long
Dim rstQuotes As DAO.Recordset
Set rstQuotes = dbLocal.OpenRecordset("tblQuotes")
strSearch = Me.txtFindText
With rstQuotes
.OpenRecordset
.MoveLast
.MoveFirst
Do Until .EOF
strQuote = .Fields("Quote")
If InStr(1, strQuote, strSearch) > 0 Then
lngQuoteID = .Fields("QUOTID")
lngAuthID = .Fields("authorid")
Exit Do
Else
.MoveNext
End If
Loop
.Close
End With
Set rstQuotes = Nothing
If Nz(lngQuoteID, 0) > 0 Then
Me.Tag = lngQuoteID
With DoCmd
.GoToControl "txtAUTHID"
.FindRecord lngAuthID
Me.Refresh
.GoToControl "sfrmQuotes"
Me.Refresh
Me.sfrmQuotes.Form.txtQUOTID.Visible = True
.GoToControl "txtQUOTID"
Me.Refresh
.FindRecord lngQuoteID
Me.SetFocus
Me.txtLName.SetFocus
Debug.Print Me.ActiveControl.Name
Me.Refresh
Me.sfrmQuotes.Form.txtQUOTID.Visible = False
End With
Else
MsgBox "The text you are searching for was not found in tblQuotes." &
vbCrLf & _
"Try a different search string. - The quote may not be in the
table.", _
vbOKOnly, "String Not Found"
End If
End Sub
It works great, insofar as it displays the correct author and quote. But the
txtQUOTD textbox I use just for searching purposes can't be made invisible at
the end of the routine. I keep getting a message saying that it can't hide
the control that has the focus. However, the code that sets the focus on
txtLName works and when I enter ?me.activecontrol.name in the debug window, I
get "txtLName". How could txtLName be the active control and yet txtQUOTID
can't be set to invisible because it "Has the focus"?
Private Sub txtFindText_AfterUpdate()
Dim strSearch As String
Dim strQuote As String
Dim lngQuoteID As Long
Dim lngAuthID As Long
Dim rstQuotes As DAO.Recordset
Set rstQuotes = dbLocal.OpenRecordset("tblQuotes")
strSearch = Me.txtFindText
With rstQuotes
.OpenRecordset
.MoveLast
.MoveFirst
Do Until .EOF
strQuote = .Fields("Quote")
If InStr(1, strQuote, strSearch) > 0 Then
lngQuoteID = .Fields("QUOTID")
lngAuthID = .Fields("authorid")
Exit Do
Else
.MoveNext
End If
Loop
.Close
End With
Set rstQuotes = Nothing
If Nz(lngQuoteID, 0) > 0 Then
Me.Tag = lngQuoteID
With DoCmd
.GoToControl "txtAUTHID"
.FindRecord lngAuthID
Me.Refresh
.GoToControl "sfrmQuotes"
Me.Refresh
Me.sfrmQuotes.Form.txtQUOTID.Visible = True
.GoToControl "txtQUOTID"
Me.Refresh
.FindRecord lngQuoteID
Me.SetFocus
Me.txtLName.SetFocus
Debug.Print Me.ActiveControl.Name
Me.Refresh
Me.sfrmQuotes.Form.txtQUOTID.Visible = False
End With
Else
MsgBox "The text you are searching for was not found in tblQuotes." &
vbCrLf & _
"Try a different search string. - The quote may not be in the
table.", _
vbOKOnly, "String Not Found"
End If
End Sub
It works great, insofar as it displays the correct author and quote. But the
txtQUOTD textbox I use just for searching purposes can't be made invisible at
the end of the routine. I keep getting a message saying that it can't hide
the control that has the focus. However, the code that sets the focus on
txtLName works and when I enter ?me.activecontrol.name in the debug window, I
get "txtLName". How could txtLName be the active control and yet txtQUOTID
can't be set to invisible because it "Has the focus"?