Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 2000 - Open form and find record

Status
Not open for further replies.

mdav2

Programmer
Aug 22, 2000
363
0
0
GB
I am an Access 97 developer and I am trying to open a form and find a record based on the value of another form.

I have tried using the same syntax listed below but it does not like the nomatch property.

Does anyone have the code which opens one form from another and goes to a specific record?

' Declare Variables
Dim FormName As String
Dim RecordNumber As Variant
Dim frm As Form
Dim rst As Recordset
Dim strCriteria As String

' Store the personid field to the variable record number
RecordNumber = Me![personid]
' Store the name of the form you want to open
FormName = "F_Person"

' Open the form
DoCmd.OpenForm FormName

' Create a recordset based on the form just opened and find the first matching record
Set frm = Forms(FormName)
strCriteria = "[PersonId] Like '*" & RecordNumber & "*'"
Set rst = frm.RecordsetClone
rst.FindFirst strCriteria

' if there is no matching records then put up a message otherwise go to the selected record.
If rst.NoMatch Then
MsgBox "Coundn't find record"
Else
frm.Bookmark = rst.Bookmark
End If

 
Open the code window in design view.
then click on the following line and press the F9 key:
Set frm = Forms(FormName)

Run it so it will go through the code and it should stop on that line.
then Press Ctrl-G to bring up the Immediate window.
to move to the next line Press F8
Now you can examine whats in each variable, put you mouse over the "strCriteria" and move is slowly after you F8 past it one line.
See if it has what it needs.
Also double check that there is infact a "Recordnumber" in your table the same as the one you are passing.


DougP, MCP
dposton@universal1.com

Ask me how Bar-codes can help you be more productive.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top