Autopopulating Field

G

Guest

Hi, I made a subform that has a button in it that when clicked will open a
different form in a new window. The subform contains a different record for
each service for the specific person listed in the main form. The button
opens a form where I can enter specific billing info every month for the
specific service number that is currently displayed. I have a table for
"services" and a table for "monthly billing" and each contain a field called
"service number". I have these 2 tables linked together by this field in the
relationships windows.

What I want to do is when I click on that button is bring up the form to
enter the specific billing details for the service number that is currently
displayed. When I do this though, the service number field in the "monthly
billing" table is not entered in automatically.

I am a beginning Access user and would like to know how to do this.

Thank You,

CEV
 
G

Guest

Thanks for the response. But now where do i do this at? And do I enter it
exactly like that but with the actual name of my forms?

Thanks,

CEV
 
J

John Vinson

Hi, I made a subform that has a button in it that when clicked will open a
different form in a new window. The subform contains a different record for
each service for the specific person listed in the main form. The button
opens a form where I can enter specific billing info every month for the
specific service number that is currently displayed. I have a table for
"services" and a table for "monthly billing" and each contain a field called
"service number". I have these 2 tables linked together by this field in the
relationships windows.

What I want to do is when I click on that button is bring up the form to
enter the specific billing details for the service number that is currently
displayed. When I do this though, the service number field in the "monthly
billing" table is not entered in automatically.

I am a beginning Access user and would like to know how to do this.

Thank You,

CEV

An additional approach to Joseph's solution (which one is more
appropriate depends on the situation) is to pass the Service Number in
the OpenArgs argument of the OpenForm method, and use the Form's Open
event to set the DefaultValue property of a control:

Dim strFormname As String
Dim strCriteria As String
strFormName = "YourSpecificForm"
strCriteria = "[Service Number] = " & Me![Service Number]
DoCmd.OpenForm strCriteria, WhereCondition := strCriteria, _
OpenArgs = Me![Service Number]
<more code>

and in YourSpecificForm's Open event

Private Sub Form_Open(Cancel as Integer)
If Me.OpenArgs & "" <> "" Then ' was an Openargs passed?
Me!txtServiceNumber.DefaultValue = Chr(34) & Me.OpenArgs & Chr(34)
End If
End Sub

Thus if the calling form's ServiceNumber is 123, the DefaultValue
property of the textbox txtServiceNumber will be set to

"123"

and new records created on the form will pick up 123 as their value.

John W. Vinson[MVP]
 
Top