rstOrder.nomatch is showing True when it should show False

C

Catherine

I have this code working properly in other databases, but it isn't working
correctly in the one I'm working on right now. When I step through the code,
intOrderID obtains the number to correspond with the record I seek. When it
moves to "If Not rstOrder.nomatch," however, it says that rstORder.nomatch =
True. When I look at the underlying table, it should be False. I have checked
the spelling of the field name on the form and on the table and I can't see
why it is True instead of False. A match should be found. Please help me find
the solution. THANKS!

'This seeks a specific customer order on a different form and takes the user
to
'the correct record. It will allow access to all records, not just the one
sought.
Dim rstOrder As DAO.Recordset
Dim frmOrder As Access.Form
Dim intOrderID As Integer

If IsNull(Me.txtName) Then
MsgBox "Please choose an order to edit.", Title:="Edit Order"
Exit Sub
End If

DoCmd.OpenForm "frmOrders"

DoEvents
Set frmOrder = Forms!frmOrders
Set rstOrder = frmOrder.RecordsetClone
intOrderID = Me.txtName.Column(1)
rstOrder.FindFirst ("OrderID=" & intOrderID)
If Not rstOrder.nomatch Then
frmOrder.Bookmark = rstOrder.Bookmark
End If

Me.txtName = Null

DoCmd.Close acForm, "frmFindOrder", acSaveNo
Set frmOrder = Nothing
Set rstOrder = Nothing
intOrderID = 0

End Sub

--Catherine
 
A

Allen Browne

Suggestions:

1. The Column() property of a combo is zero-based.
Did you mean:
intOrderID = Me.txtName.Column(0)

2. If the form is filtered, the order may not be found.

3. Drop the DoEvents, which I think you added to give the form time to load
its records. Instead, try this a few lines later:
rstOrder.MoveLast
That should force all the records to load.

4. You could also try without the parentheses:
rstOrder.FindFirst "OrderID=" & intOrderID
 
C

Catherine

Allen,
Thank you for your suggestions. Before I got your response, I found a
solution that also works. I may implement yours just to test them.

In answer to your questions, I did reference the correct column (2nd column)
remembering that combo boxes are zero-based. The form is not filtered. I will
try the other two options for curiosity sake.

The solution I found, that so far does not need to be implemented anywhere
else I have this code snippet, is to open my form with DataMode:=acFormEdit.
I honestly don't know why this form requires it when no other form requires
it, but it seems to work now. THANK YOU for your suggestions! :)

--Catherine
 
A

Allen Browne

Okay: your solution makes sense if the form's DataEntry property is set to
No. In that case the form loads without any records, so the FindFirst fails.
 

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

Top