FindRecord Code problem

J

Jim

I am converting a database from 97 to XP. I have a pop
up form that I use to help people find records. It works
fine in 97 and other XP databases. I am having trouble
with only one database and it is driving me nuts.

I get an error message "A macro set to one of the current
field properties failed because of an error in a
FindRecord action argument. The frustrating part about
it is if I set the code to stop at the find record code
line, goto debug when it stops and then continue the code
without making any changes it works fine. If I take out
the temporary stop for that line of code I get the error.

The code is as follows:

DoCmd.OpenForm stDocName, acNormal
Forms![frmProdInfo]![cboOrderID].Enabled = True
Forms![frmProdInfo]![cboOrderID].Locked = False
Forms![frmProdInfo]![cboOrderID].SetFocus
'THE FOLLOWING LINE GIVES THE ERROR. FWhat is the ID
for 'the control (combo box)
DoCmd.FindRecord FWhat, acAnywhere, False, , False, , True

Forms![frmProdInfo]![tbPlant].SetFocus
Forms![frmProdInfo]![cboOrderID].Locked = True
Forms![frmProdInfo]![cboOrderID].Enabled = False

All suggestions are welcome.

Jim
 
D

Dirk Goldgar

Jim said:
I am converting a database from 97 to XP. I have a pop
up form that I use to help people find records. It works
fine in 97 and other XP databases. I am having trouble
with only one database and it is driving me nuts.

I get an error message "A macro set to one of the current
field properties failed because of an error in a
FindRecord action argument. The frustrating part about
it is if I set the code to stop at the find record code
line, goto debug when it stops and then continue the code
without making any changes it works fine. If I take out
the temporary stop for that line of code I get the error.

The code is as follows:

DoCmd.OpenForm stDocName, acNormal
Forms![frmProdInfo]![cboOrderID].Enabled = True
Forms![frmProdInfo]![cboOrderID].Locked = False
Forms![frmProdInfo]![cboOrderID].SetFocus
'THE FOLLOWING LINE GIVES THE ERROR. FWhat is the ID
for 'the control (combo box)
DoCmd.FindRecord FWhat, acAnywhere, False, , False, , True

Forms![frmProdInfo]![tbPlant].SetFocus
Forms![frmProdInfo]![cboOrderID].Locked = True
Forms![frmProdInfo]![cboOrderID].Enabled = False

All suggestions are welcome.

I'm not sure, but maybe in this particular database the form's recordset
isn't loaded yet or something like that. You could try adding the
statement

DoEvents

after the call to DoCmd.OpenForm.

However, you could try using the form's recordset to locate the record
you want, instead of FindRecord. Code might look something like this:

DoCmd.OpenForm stDocName, acNormal
Forms(stDocName).Recordset..FindFirst "OrderID Like " & FWhat

That way you wouldn't have to monkey around with unlocking a combo box
that is normally supposed to be locked and disabled.

Note that, if OrderID is a text field, the FindiFirst criterion would
have to enclose it in quotes, possibly like this:

Forms(stDocName).Recordset..FindFirst "OrderID Like '" & FWhat & "'"

Note also -- I've used the "Like" operator in the FindFirst criterion,
because your FindRecord call used acAnywhere for the Match argument. If
FWhat isn't going to use any wild-card characters, but rather is just an
OrderID, replace "Like" with "=" in the criterion.

Another possible approach to this problem would be to open the form
showing only the record(s) whose OrderID matches FWhat, by using the
WhereCondition argument of the OpenForm call. The fact that you're not
doing this suggests that you want the user to be able to move to other,
nonmatching records on the form. That's fine, but I just thought I'd
mention it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

FindRecord Error 2
ByPass key ms access 2016 0
Findrecord giving a msg 1
Locking/Enabling Combo Box in Form 6
Debug Code 2
FindRecord problem 2
Help with FindRecord 1
Form with two nested subforms. 8

Top