copy value from form to subform

theinviter

Registered User.
Local time
Today, 10:37
Joined
Aug 14, 2014
Messages
273
Hi guys;

need help please

i have a form and subform, so i created a button to add the value from from to specific filed in subform in new record , i tried the below code but got this error code "the setting you entered isnt valid for this property"


Private Sub Command1608_Click()

Me.[cycle subform].Form.Cycle = Me.No_of_Cycle.Value
Me.[cycle subform].Form.date_ = Date

End Sub

how to solve this issue
 
Try bracketing "Cycle". It's a reserved word, as it is a property of the form.
 
Hi. Do you know which one is causing the error? If not, try them out one at a time. Maybe it has something to do with the data.
 
done i changed the field to cycle1 but i want the date upon click it go to new reccod in subform and paste the value.
how to do that
 
Do NOT dirty records before the user does. If you want to copy a field from the main form to the subform, do it in the subform's BeforeInsert event. This event runs immediately when the user types the first character into any subform field.

Me.[cycle] = Me.Parent![Cycle]
Me.[Date_] = Date

Notice the trailing underscore (_) at the end of your date field. That happened because whatever you used in that position in your column name is a prohibited character. Rather than disallowing the name(that would have been my choice), Access is "nice" to you and accepts the bad character but converts it to something it can use.

Proper object names include ONLY the letters (upper or lower case), numbers (0-9), and the underscore (_). NO other character is valid as an object name in VBA. That is why Access converts them to underscores in some cases and in others just allows you to encapsulate them in square brackets.
 
i tried this code but did not work


Me.[cycle subform].SetFocus
DoCmd.GoToControl ([Cycle1])
DoCmd.GoToRecord , , acNew
Me.[cycle subform].Form.Cycle1 = Me.No_of_Cycle.Value
Me.[cycle subform].Form.date_ = Date

End Sub
 
done guys

thank you

i done with this code:
On Error GoTo new_Err

Me.[cycle subform].SetFocus 'sets the focus to sfrm_Each_Book_subform
DoCmd.RunCommand acCmdRecordsGoToNew
new_Err:
Me.[cycle subform].Form.Cycle1 = Me.No_of_Cycle.Value
Me.[cycle subform].Form.date_ = Date
 
Glad you are happy but just because it seems to work, doesn't mean that the solution is sound. YOU are dirtying a record rather than the user This code will end up creating "empty" records if the user fails to enter the rest of the necessary data. At least add validation logic to the subform's BeforeUpdate event to ensure that necessary fields are filled in.
 

Users who are viewing this thread

Back
Top Bottom