Searchbox stops working!

dayna

Registered User.
Local time
Today, 04:59
Joined
Nov 10, 2007
Messages
39
I’ve been working on a little application in Access 2007 for a couple months now, and I continue to be vexed by a mysterious problem: every now and then, the comboboxes that I use to find records stop working. To be more specific, the comboboxes themselves work, but the form continues to display the current record rather than navigating to the record selected from the combobox.

Basically, I have several similar forms that are used to view single records. (These forms are not related to each other, but they are all designed the same way, and I’ve had this problem with all of them.) Each form has a couple of subforms (in case that matters) and each has a command button named cmdFind. Because all of these forms are opened in read-only mode, cmdFind sets the AllowEdits property of the main form to True and makes the searchbox visible.

The searchbox is a combobox that I originally created using the third option of the combobox wizard. I added a couple of actions to the embedded macro to make the findbox invisible after an update, and I use an event procedure in the combobox’s LostFocus event to set AllowEdits back to false.

As I mentioned, this method works just fine for a (seemingly random) period of time, then inexplicably stops working. When I click cmdFind, the searchbox show up, but when a selection is made, all the other actions execute, but the form does not go to the specified record. Instead, the current record reloads. :confused:

I haven’t found another thread that describes this problems, so in the past, I’ve addressed it by deleting the searchbox and re-creating it. To my frustration, this solution has proven to be temporary, and I’m finally irritated enough to figure out why.

I’m sure you’ll be glad to know that I’ve converted all my macros to VBA (and trying to break the habit of using them altogether). Since the DoCmd.SearchForRecord bit that the converter tool came up with didn’t work, I starting using the Me.RecordsetClone.FindFirst bit that I’ve found in this thread and others like it.

That works well (for now, anyway) on two of the three forms. One of my forms is holding out, though, and is still doing what I described above. I’ll post this form’s code for good measure, but I’m thinking the problem has to be elsewhere. It’s probably something simple. Any ideas?


Code:
Private Sub cmdFind_Click()
Me.AllowEdits = True
Me.cboFindEmp.Visible = True
Me.cboFindEmp.SetFocus
Me.cmdNew.Enabled = False
Me.cmdEdit.Enabled = False
Me.cmdPrint.Enabled = False
Me.cmdDone.Enabled = False
Me.cmdCancel.Visible = True
Me.cmdFind.Enabled = False
End Sub


Private Sub cboFindEmp_AfterUpdate()
On Error GoTo cboFindEmp_AfterUpdate_Err
Me.RecordsetClone.FindFirst "[StaffID] = " & Me![cboFindEmp]
Me.Bookmark = Me.RecordsetClone.Bookmark
    DoCmd.SetProperty "cmdNew", acPropertyEnabled, "-1"
    DoCmd.SetProperty "cmdEdit", acPropertyEnabled, "-1"
    DoCmd.SetProperty "cmdFind", acPropertyEnabled, "-1"
    DoCmd.SetProperty "cmdDone", acPropertyEnabled, "-1"
    DoCmd.SetProperty "cmdPrint", acPropertyEnabled, "-1"
    DoCmd.GoToControl "txtEmpName"
    DoCmd.SetProperty "cmdCancel", acPropertyVisible, "0"
    DoCmd.SetProperty "cboFindEmp", acPropertyVisible, "0"
cboFindEmp_AfterUpdate_Exit:
    Exit Sub
cboFindEmp_AfterUpdate_Err:
    MsgBox Error$
    Resume cboFindEmp_AfterUpdate_Exit
End Sub


Private Sub cboFindEmp_LostFocus()
Me.AllowEdits = False
End Sub
 

Users who are viewing this thread

Back
Top Bottom