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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a passed variable to change the viewed record in a form

Status
Not open for further replies.

Wally0

Programmer
Aug 6, 2001
9
US
There are several disscussion on using cobo boxes to change information viewed in a form. In my case, I'm using a pop-up form (with a cobo box) to retrieve a record number. I can successfully pass this value to the form. However, I'm stumped on how to change the current record to a different record based on the "record number." Here are some of the methods that I've tried:

Me.Filter = "[RecordNumber] = varIndex'"
Me.FilterOn = True

also

Dim db As Database
Dim rs As Recordset
Dim strSQL As String

strSQL = "SELECT * FROM [tblMain] WHERE RecordNumber = " & varIndex & ""

Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL)

This has to be something simple -- I'm just missing what it is. Thanks for any assistance

Wally
 
I can't think of the code off hand. But look up the recordset.clone in the help. I think that's how I normally do it. Something like:

Nick
 
I can't think of the code off hand. But look up the recordset.clone in the help. I think that's how I normally do it.

Nick
 
Thanks Nick for the tip.. I tried using the RecordSource property and modified the code a little and it worked:

Dim strSQL As String

strSQL = "SELECT * FROM [tblMain] WHERE RecordNumber = " & varIndex & ""

Dim strNewRecord As String
strNewRecord = (strSQL)
Me.RecordSource = strNewRecord



Wally


 
Wally,

That's good. Another way is like:
dim rs as object
dim sRef as string

sRef = me.openargs

Set rs = Me.Recordset.Clone
rs.FindFirst "[ref_number] = '" & sRef & "'"
Me.Bookmark = rs.Bookmark

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top