Open form to specific record

G

Gibson

I am using the following code to open up a recordset, add a record then open
a form based upon that table.

Dim rsImp As ADODB.Recordset
Dim SQLStmnt As String
strNewData = NewData
SQLStmnt = "SELECT * FROM flkp1 WHERE Field1 = '" & strNewData &
"'"
Set rsImp = New ADODB.Recordset
rsImp.Open SQLStmnt, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
If rsImp.EOF Then
rsImp.AddNew
rsImp![Field1] = strNewImp
rsImp.Update
End If
rsImp.Close
Set rsImp = Nothing

DoCmd.OpenForm "frm1", acNormal, "", "", , , "Field1 =
strNewData"

The record is added fine but the form opens to the most recent record, not
the record whose Field1 value is equal to strNewData. Field 1 is the key
field in the table. Any ideas?

Thanks
 
G

George Nicholson

You are using OpenArgs to pass information to the Form ("Field1 =
strNewData"), but you aren't doing anything with that information. In the
Open event of the form you would need to add something like:
Me.Filter = Me.OpenArgs

Review the OpenArgs property of Forms and it's examples.

HTH,
--
George Nicholson

Remove 'Junk' from return address.


Gibson said:
I am using the following code to open up a recordset, add a record then
open a form based upon that table.

Dim rsImp As ADODB.Recordset
Dim SQLStmnt As String
strNewData = NewData
SQLStmnt = "SELECT * FROM flkp1 WHERE Field1 = '" & strNewData
& "'"
Set rsImp = New ADODB.Recordset
rsImp.Open SQLStmnt, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
If rsImp.EOF Then
rsImp.AddNew
rsImp![Field1] = strNewImp
rsImp.Update
End If
rsImp.Close
Set rsImp = Nothing

DoCmd.OpenForm "frm1", acNormal, "", "", , , "Field1 =
strNewData"

The record is added fine but the form opens to the most recent record, not
the record whose Field1 value is equal to strNewData. Field 1 is the key
field in the table. Any ideas?

Thanks
 

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