here is my full code allen
Private Sub Command7_Click()
'dec
Dim rs As Recordset
Dim rstr As String
Dim fcode As Integer
Dim fname As String
Dim tcode As Integer
Dim tname As String
'init
fcode = Me.Text4.Value
fname = Me.text5.Value
tcode = Me.Text3.Value
rstr = "SELECT Users.[First Name], Users.Surname, Users.Usercode FROM
Users
WHERE Users.Usercode=" & tcode & ";"
'recordset to find users name
Set rs = CurrentDb.OpenRecordset(rstr)
tname = rs.Fields("First Name")
tname = tname & " " & rs.Fields("Surname")
'switch forms
DoCmd.OpenForm "equip_tfr_3", acNormal, , , acFormAdd, acWindowNormal
DoCmd.Close acForm, "Equip_tfr_2", acSaveNo
'populate next form
Forms!equip_tfr_3.Text3 = fcode
Forms!equip_tfr_3.Text4 = fname
Forms!equip_tfr_3.text5 = tcode
Forms!equip_tfr_3.text6 = tname
'close recordset
rs.Close
'build subform
rstr = "SELECT Transactions.Transcode, Transactions.Usercode,
Transactions.[Out date], Transactions.transfer FROM Transactions WHERE
Transactions.Usercode= " & fcode & ";"
Set rs = CurrentDb.OpenRecordset(rstr)
Set Forms!equip_tfr_3.[Child20].Form.Recordset = rs
Forms!equip_tfr_3.[Child20].Form.Refresh
'clear the recordset
rs.Close
Set rs = Nothing
End Sub
i based it on another piece of code that yourself and dirk goldgar helped
me
with
http://www.microsoft.com/communitie...3bc70e8bebb1&lang=en&cr=US&sloc=en-us&m=1&p=1
here is the other piece of code that works perfectly
Private Sub Command7_Click()
'dec
Dim rs As Recordset
Dim ucode As Integer
Dim qry1 As String
Dim qry2 As String
Dim Name As String
'init
ucode = Me.Text3
qry1 = "SELECT Users.[First Name], Users.Surname, Users.Usercode FROM
Users
WHERE Users.Usercode=" & ucode & ";"
qry2 = "SELECT Transactions.Usercode, Transdata.Barcode, Transdata.[In]
FROM
Transactions INNER JOIN Transdata ON Transactions.Transcode =
Transdata.Transcode WHERE Transactions.Usercode =" & ucode & "AND
Transdata.[In] Is Null;"
'init recordset to find users name
Set rs = CurrentDb.OpenRecordset(qry1)
Name = rs.Fields("First Name")
Name = Name & " " & rs.Fields("Surname")
rs.Close
'init recordset to populate subform
Set rs = CurrentDb.OpenRecordset(qry2)
'switch forms
DoCmd.OpenForm "equip_in_2", acNormal, , , acFormAdd, acWindowNormal
DoCmd.Close acForm, "equip_in_1", acSaveNo
'populate new form
Forms!equip_in_2.Text3 = ucode
Forms!equip_in_2.Text7 = Name
Set Forms!equip_in_2.[Child20].Form.Recordset = rs
'clear recordset
rs.Close
Set rs = Nothing
End Sub
i cant understand why it worked the last time but not this time. i believe
i
am using the same method. they only different this time is the
sub-subform.
Allen Browne said:
How have you declared your rstr variable? If it's declared within a
procedure, it ceases to exist once the procedure ends, so there's nothing
left to assign to your form.
Try declaring it in the General Declarations section of a standard module
(not the module of a form/report):
dim gDb As DAO.Database
Dim gRst AS DAO.Recordset
Then start with a stand-alone form (not as a subform) and in its Open
event
assign the recordset variable and assign it to the form:
Private Sub Form_Open(Cancel As Integer)
Set gDb = CurrentDb()
Set gRs = gDb.OpenRecordset(strSql)
Me.Recordset = gRs
End Sub
with the matching code to close recordset and set both objects to Nothing
in
Form_Close (with error handling in case it got reset.)
Once you get that working, you can try it as a subform. However, you will
not be able to use anything in the subform control's
LinkMasterFields/LinkChildFields. If you use these properties, Access
reloads the subform every time the record in the main form changes, so
you
attempt to set the Recordset does not survive.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
Joseph Atie said:
i have a piece of vba code that collects a variable and uses that
variable
to
generate a recordset.
So far so good
now i want to use that record set to populate a subform. problem is it
all
seems to work except instead of getting my data i get #name?
what am i doing wrong?
here is the code
rstr = "SELECT Transactions.Transcode, Transactions.Usercode,
Transactions.[Out date], Transactions.transfer FROM Transactions WHERE
Transactions.Usercode= " & fcode & ";"
Set rs = CurrentDb.OpenRecordset(rstr)
Set Forms!equip_tfr_3.[Child20].Form.Recordset = rs
the subform is unbound and not linked to the main form, but the fields
are
bound to the names of the recordset columns.