T
TriX
Hello all.
I have a form with a "order number" field which i'm basing my searches on. I
successfully created a pop-up form that searches for a specified order number
and pulls the corresponding record (works alot like built in find feature).
The problem i am having, is that if the user searches for a order number that
doesn't exist, there is absolutly no feedback. When something isn't found
after they click search, nothing happens or changes. I was wondering if
someone could help me add a dialogue box promting the user a record can't be
found if its not there. Thanks so much.
Code (as found on the search form's, search button (onClick event):
Option Compare Database
Option Explicit
Dim mstrFormToSearch As String
Private Sub cmdFind_Click()
Static strLastFind As String
Dim ctlFocus As Access.Control
Dim strTemp As String
Dim I As Integer
If IsNull(Me.txtFindWhat) Then Exit Sub
With Forms(mstrFormToSearch)
.SetFocus
Set ctlFocus = .ActiveControl
On Error Resume Next
strTemp = ctlFocus.ControlSource
If Err.Number <> 0 Then
For I = 0 To .Controls.Count - 1
Set ctlFocus = .Controls(I)
If ctlFocus.Enabled = True Then
Err.Clear
strTemp = ctlFocus.ControlSource
If Err.Number = 0 Then
Exit For
End If
End If
Next I
End If
ctlFocus.SetFocus
On Error GoTo 0
End With
If Me.txtFindWhat = strLastFind Then
DoCmd.FindNext
Else
DoCmd.FindRecord _
Me.txtFindWhat.Value, _
acAnywhere, _
False, _
acSearchAll, _
False, _
acAll, _
True
strLastFind = Me.txtFindWhat
End If
End Sub
I have a form with a "order number" field which i'm basing my searches on. I
successfully created a pop-up form that searches for a specified order number
and pulls the corresponding record (works alot like built in find feature).
The problem i am having, is that if the user searches for a order number that
doesn't exist, there is absolutly no feedback. When something isn't found
after they click search, nothing happens or changes. I was wondering if
someone could help me add a dialogue box promting the user a record can't be
found if its not there. Thanks so much.
Code (as found on the search form's, search button (onClick event):
Option Compare Database
Option Explicit
Dim mstrFormToSearch As String
Private Sub cmdFind_Click()
Static strLastFind As String
Dim ctlFocus As Access.Control
Dim strTemp As String
Dim I As Integer
If IsNull(Me.txtFindWhat) Then Exit Sub
With Forms(mstrFormToSearch)
.SetFocus
Set ctlFocus = .ActiveControl
On Error Resume Next
strTemp = ctlFocus.ControlSource
If Err.Number <> 0 Then
For I = 0 To .Controls.Count - 1
Set ctlFocus = .Controls(I)
If ctlFocus.Enabled = True Then
Err.Clear
strTemp = ctlFocus.ControlSource
If Err.Number = 0 Then
Exit For
End If
End If
Next I
End If
ctlFocus.SetFocus
On Error GoTo 0
End With
If Me.txtFindWhat = strLastFind Then
DoCmd.FindNext
Else
DoCmd.FindRecord _
Me.txtFindWhat.Value, _
acAnywhere, _
False, _
acSearchAll, _
False, _
acAll, _
True
strLastFind = Me.txtFindWhat
End If
End Sub