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

Populate sub form from main form

Status
Not open for further replies.

hansretallick

Technical User
Jan 9, 2006
33
GB
I need to populate severeal fields in a sub form as an after update event procedure from a combo box. The main form sets fields as a result of the combo update - one example is CloseDate which I need to be inserted into a CloseDate field in a sub form.

I have tried this code, but it doesn't work:-
Dim RS As Recordset
Me.Dirty = False
Forms![frmInvoiceLandlord]![frmSubInvoiceLandlordDates].SetFocus
Forms![frmInvoiceLandlord]![frmSubInvoiceLandlordDates].Form![OpenDate].SetFocus
Do While Not RS.EOF
With RS
frmSubInvoiceLandlordDates.Form!OpenDate = Me.OpenDate
frmSubInvoiceLandlordDates.Form!CloseDate = Me.CloseDate
End With
Loop
RS.Close

So far I haven't had any success. Any ideas?
 
me.subformcontrolname.form.opendate=me.opendate
 
Many mate, many!

Code:
[red]dim db as database[/red]
Dim RS As Recordset

[red]set db=currentdb
set rs=db.openrecordset(query,dbopendynaset) 'what do you want your recordset to be?
'[/red]Me.Dirty = False 'dirty is a read only property, can't be set
[red]'[/red]Forms![frmInvoiceLandlord]![frmSubInvoiceLandlordDates].SetFocus 'pointless as you then se the focus elsewhere
[red]'[/red]Forms![frmInvoiceLandlord]![frmSubInvoiceLandlordDates].Form![OpenDate].SetFocus 'why?
[red]rs.movefirst[/red]
Do While Not RS.EOF
 With RS
      [red]'from this point on you do nothing with the rs?[/red]
     
      'frmSubInvoiceLandlordDates.Form!OpenDate = Me.OpenDate
      'frmSubInvoiceLandlordDates.Form!CloseDate = Me.CloseDate
    End With
[red]'fatal error!  Always advance when in a loop otherise you'll rot waiting
    rs.movenext[/red]

Loop

if you can sort those couple of dramas out, perhaps with message box in the middle of the business loop to confirm you're going through your form or recordset, then we're all happy to help further

Please dont think i'm being mean or difficult, I just need you to get to grips with where you're aiming at before i can help you get there

See ya soon, JB
 
Many thanks. I did try that before, but it didn't work. It still didn't work with your code, but on looking at the sub form again, I discovered that it's record source had become bound (lovely Access "help" I guess. Unbound the form and it worked perfectly. Many thanks.
 
Also many thanks, JB for your help with the code - not my strong point, I'm afraid.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top