Andy,
' move to some other control to be able to be able to set
' ReportNo Enabled property to false. Change to whatever
' control you want
Me.cmdGotoRecord.SetFocus
Do I need to enter something myself?
You cannot set the Enabled property of a control to FALSE if it has the focus. So I set the focus to the button - you can set the focus to any control except disabled controls or the control you are trying to disable.
Do you *have* to use an Input box? Have you thought about using a combo box? How many unique report numbers are there?
In a *copy* of your database, open the form that has the button "cmdGotoRecord". Next to it, add a combo box.
Name it "cboSelectRptNo" (no quotes).
Set the Row Source property to:
SELECT DISTINCT YourTableName.ReportNo FROM YourTableName ORDER BY YourTableName.ReportNo;
Set the "Limit To List" and :Auto Expand" properties to YES.
Next, change the button code to:
Code:
Private Sub cmdGotoRecord_Click()
On Error GoTo Err_cmdGotoRecord_Click
Dim strReport As Integer
Dim tmp As Integer
strReport = Me.cboSelectRptNo
'abort if number not selected
If Len(Trim(strReport)) = 0 Then
MsgBox "Report number Not Selected"
End If
'get current ReportNo
tmp = Me.ReportNo
Me.ReportNo.Enabled = True
Me.ReportNo.SetFocus
DoCmd.FindRecord strReport
' move to some other control to
' be able to be able to set
' ReportNo Enabled to false
Me.cmdGotoRecord.SetFocus
Me.ReportNo.Enabled = False
'check if the report no. was found and
If (tmp = Me.ReportNo) And (Me.ReportNo <> strReport) Then
MsgBox "Report number " & strReport & " Not found"
End If
Exit_cmdGotoRecord_Click:
Exit Sub
Err_cmdGotoRecord_Click:
MsgBox Err.Description
Resume Exit_cmdGotoRecord_Click
End Sub
The combo box automatically validates the entry.
Will this work for you?