copy field data from main form to a subform on add new record

pb21

Registered User.
Local time
Today, 14:53
Joined
Nov 2, 2004
Messages
122
I have a main form that has some sub forms on it linked by master child on PK. When I select a new record on the sub forms I want to take a date value from the main form and populate the value into a field in the sub form. How do I do this as I cannot see a new record event on the sub form?

help would be much appreciated.
regards

Peter
 
Try using the OnCurrent event of the SubForm:
If Me.NewRecord Then
Pull Date from the Parent form
End If
 
on current event of subform

The subform now grabs the date field values from my parent form on the oncurrent event of the subform with the following:

Dim StrDateFrom As String
Dim StrDateTo As String


If Me.NewRecord Then
Forms![Group Main Screen Form]![Arrival Date].SetFocus
StrDateFrom = Forms![Group Main Screen Form]![Arrival Date]
StrDateTo = Forms![Group Main Screen Form]![Departure Date]
Me.From.SetFocus
Me.From.Text = StrDateFrom
Me.To.SetFocus
Me.To.Text = StrDateTo
End If


This works as advised but if i try and delete a record it also runs the if statement as well and creates a new record bizarrly.

I cannot see why as clearly the if statement says me.newrecord.

advice on this peculiarity would be welcome.

regards in advance
Peter
 
Let's try simplifying your code just a bit.
Code:
If Me.NewRecord Then
   Me.From = Me.parent![Arrival Date]
   Me.To = Me.parent![Departure Date]
End If
Try that and see if you still have the same symptom.
 
if evaluates incorrectly on add record

Hi rural (or anyone else) yes, even with the simplified code if i select the row i want to delete the oncurrent event runs and the if does not evaluate true, however once i click delete the if evaluates true and the code runs, its strange.

regards

If Me.NewRecord Then
Me.From = Me.Parent![Arrival Date]
Me.To = Me.Parent![Departure Date]
End If
 
Try moving the code to the SubForms BeforeUpdate event and see if the extra record goes away. Deleting records causes extra Current events that I've had to work around before. You won't see the dates until the record is saved though.
 
Problem cured rural as you said on before update event.

thank you so much
 

Users who are viewing this thread

Back
Top Bottom