recordset based form VB code

R

rmanchu

hi

v Access 2003

i've got a form which to which i attach a Recordset at runtime. ok upto
here
another form also. ok upto here

now i want to combine them in a single form in form/subform manner.

Private Sub Form_Open(Cancel As Integer)
Set Me.Recordset = rstSection
Me.SectionStaff.LinkMasterFields = "Section_CodeE"
Me.SectionStaff.LinkChildFields = "SecStaff_Section"
End Sub

however, on line two (LinkMasterFields), i get an error (31) saying
"Data Provider could not be initialised"

Private Sub Form_Open(Cancel As Integer)
Set Me.Recordset = rstSectionStaff
End Sub

the subform ^above^code^ is called correctly as well and before the
main form open method is called.

the fieldnames ARE correct - when i load the form/subform from *linked
tables* it works fine. i just cannot get VB code above to work. please
help.

halp
riyaz
 
A

Albert D.Kallal

I believe that when you set a forms reocrdset via code, then you can't use
the link master/child fields.

However, I suppose that since you are using code...then you just setup
"defaults" in the sub forms "on insert" event to set the foreign key
field...
 
R

rmanchu

hello

can u explain what u mean by "setup defaults in the sub forms on insert
event"?

do u mean like get the value of the linked field from the main form and
set that up?

if so, then i'll have to write a little code to filter the subform such
that only the "linked records" are shown in the subform?

am on the right track?

thanx
riyaz
 
A

Albert D.Kallal

can u explain what u mean by "setup defaults in the sub forms on insert
event"?

do u mean like get the value of the linked field from the main form and
set that up?

Yes. So, in the sub forms "before insert" event (this event fires when the
user starts to type data), you could go:

me!FKID = me.parent!ID
if so, then i'll have to write a little code to filter the subform such
that only the "linked records" are shown in the subform?

Yes...you will have to do the above also.....
 
R

rmanchu

hi. thanx for the reply
Yes...you will have to do the above also.....

i'm having trouble with the above part.
note that i'm using Recordset objects attached at runtime for both
parent n child forms

-- parent form; "SectionStaff" is the subform object
Private Sub Form_Current()
Me.SectionStaff.Form.Filter = "SecStaff_Section='" &
me.Staff_CodeE.Value & "'"
End Sub

this does seem to filter the subform; ie all records r displayed; so i
changed it

Private Sub Form_Current()
Me.SectionStaff.Form.Filter = "SecStaff_Section='" &
me.Staff_CodeE.Value & "'"
Me.SectionStaff.Form.FilterOn = True
End Sub

but this does not seem to work either :(

is it possible to c an example on this?
what am i doing wrong?

thanx n haalp
riyaz
 

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