Get value from Recordset for later use

A

Ayala

Hi,

I have to autonumber fields in two different tables, each
primary key field are called ProjectDataID and GenDataID.

the relationship between the two tables is one to many.

I have this code. And I need to get the GenDataID value
that access is assigning for then open the form with the
where condition set to this value (GenDataID = ??).

My code looks like this:

Private Sub cmdAddService_Click()
Dim strSQL As String

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open "Select * from tblGeneralData Where
GenDataID = 0"
.AddNew
!ProjectDataID = Me.ProjectDataID
.Update
End With ' until here the GenDataID is created and assigned
' to the proper ProjectDataID. Here is where I need to
'pick the value assigned to GenDataID to open the form.
'I try with no luck this:
'strSQL = "GenDataID Like " & rst.GenDataID
'or
'strSQL = "GenDataID Like " & rst(GenDataID)
'or
'strSQL = "GenDataID Like " & rst[GenDataID]

DoCmd.OpenForm "frmGeneralData", acNormal, , strSQL

rst.Close
End Sub

PLEASE I'VE BEEN TRYING TO SOLVE THIS FOR VERY LONG.
I NEED YOUR HELP.
THANK YOU.
 
S

Scott McDaniel

Try rst("GenDataID") ... although I really have no idea what you're trying
to accomplish.
 
G

Guest

I'm trying to "attach" a new GenDataID to an existing
ProjectDataID...
-----Original Message-----
Try rst("GenDataID") ... although I really have no idea what you're trying
to accomplish.

Hi,

I have to autonumber fields in two different tables, each
primary key field are called ProjectDataID and GenDataID.

the relationship between the two tables is one to many.

I have this code. And I need to get the GenDataID value
that access is assigning for then open the form with the
where condition set to this value (GenDataID = ??).

My code looks like this:

Private Sub cmdAddService_Click()
Dim strSQL As String

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open "Select * from tblGeneralData Where
GenDataID = 0"
.AddNew
!ProjectDataID = Me.ProjectDataID
.Update
End With ' until here the GenDataID is created and assigned
' to the proper ProjectDataID. Here is where I need to
'pick the value assigned to GenDataID to open the form.
'I try with no luck this:
'strSQL = "GenDataID Like " & rst.GenDataID
'or
'strSQL = "GenDataID Like " & rst(GenDataID)
'or
'strSQL = "GenDataID Like " & rst[GenDataID]

DoCmd.OpenForm "frmGeneralData", acNormal, , strSQL

rst.Close
End Sub

PLEASE I'VE BEEN TRYING TO SOLVE THIS FOR VERY LONG.
I NEED YOUR HELP.
THANK YOU.


.
 

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