Call Function. How does this code work.

A

Ayo

Do anyone know how this works and if so, is it correct the way it is written?
Private Sub CommandButton_Click()
Call DoCmd.OpenForm("Form2")
Forms![Form2]![txtBox1]=Me("txtBox1")
Forms![Form2]![txtBox1]=Me("txtBox1")
End Sub
I saw this somewhere else and I am contemplating using it in my project but
I don't really understand the call function here. There are no commas or
anything seperating the Call and the expressions. That is why I am not sure
is it is right or not.
Any help wil be greatly appreciated. Thank you.
Ayo
 
F

fredg

Do anyone know how this works and if so, is it correct the way it is written?
Private Sub CommandButton_Click()
Call DoCmd.OpenForm("Form2")
Forms![Form2]![txtBox1]=Me("txtBox1")
Forms![Form2]![txtBox1]=Me("txtBox1")
End Sub
I saw this somewhere else and I am contemplating using it in my project but
I don't really understand the call function here. There are no commas or
anything seperating the Call and the expressions. That is why I am not sure
is it is right or not.
Any help wil be greatly appreciated. Thank you.
Ayo

No Call is needed.

Private Sub CommandButton_Click()
DoCmd.OpenForm "Form2"
Forms![Form2]![txtBox1]=Me![txtBox1]
End Sub

Those 2 lines will open a form named "Form2" and pass to that form's
[txtBox1] control whatever data is shown in this form's [txtBox1]
control.

Is that what you wish to do?
I have no idea why the second line was repeated.

It would be wise to first learn and understand what code does before
attempting to use it.

If you now understand it and it is not what you are trying to do, then
post back with more information.
 
A

Ayo

Sorry about that. What I meant to write was:
Call DoCmd.OpenForm("Form2")
Forms![Form2]![txtBox1]=Me("txtBox1")
Forms![Form2]![txtBox2]=Me("txtBox2")
Forms![Form2]![txtBox3]=Me("txtBox3")
Forms![Form2]![txtBox4]=Me("txtBox4")

I want to use it for multiple entries


fredg said:
Do anyone know how this works and if so, is it correct the way it is written?
Private Sub CommandButton_Click()
Call DoCmd.OpenForm("Form2")
Forms![Form2]![txtBox1]=Me("txtBox1")
Forms![Form2]![txtBox1]=Me("txtBox1")
End Sub
I saw this somewhere else and I am contemplating using it in my project but
I don't really understand the call function here. There are no commas or
anything seperating the Call and the expressions. That is why I am not sure
is it is right or not.
Any help wil be greatly appreciated. Thank you.
Ayo

No Call is needed.

Private Sub CommandButton_Click()
DoCmd.OpenForm "Form2"
Forms![Form2]![txtBox1]=Me![txtBox1]
End Sub

Those 2 lines will open a form named "Form2" and pass to that form's
[txtBox1] control whatever data is shown in this form's [txtBox1]
control.

Is that what you wish to do?
I have no idea why the second line was repeated.

It would be wise to first learn and understand what code does before
attempting to use it.

If you now understand it and it is not what you are trying to do, then
post back with more information.
 
J

John W. Vinson

Sorry about that. What I meant to write was:
Call DoCmd.OpenForm("Form2")

Again: no Call is needed. DoCmd is a statement in its own right; you don't
"Call" it, just put

DoCmd.OpenForm("Form2").
Forms![Form2]![txtBox1]=Me("txtBox1")
Forms![Form2]![txtBox2]=Me("txtBox2")
Forms![Form2]![txtBox3]=Me("txtBox3")
Forms![Form2]![txtBox4]=Me("txtBox4")

The proper syntax would be

Forms![Form2]![txtBox4]=Me!txtBox4

though the parenthesis notation might be acceptable.
I want to use it for multiple entries

Well... you almost surely DON'T.

The only reason I can think of to do this is to copy data from Form1's
Recordsource into another table (Form2's Recordsource), storing a redundant
duplicate copy of the data.

It's almost never a good idea to do so; and - if you DO need to do so - it's
much better not to get Forms involved at all, but instead run an Append query
to append one or more records from the first table directly into the second
table.

What's the purpose of this exercise? What are you trying to accomplish?

John W. Vinson [MVP]
 
A

Ayo

This is what I have and it is working fine.
Call DoCmd.OpenForm("Invoice by Dates")
Forms![Invoice by Dates]![txtSingleDate] = Me.txtSingleDate
Forms![Invoice by Dates]![txtBeginDateRange] = Me.txtStartDate
Forms![Invoice by Dates]![txtEndDateRange] = Me.txtEndDate
Forms![Invoice by Dates]![logic_Value] = Me.cmbLogical
Forms![Invoice by Dates]![txtVendor] = Me.cmbVendor
Forms![Invoice by Dates]![txtReviewer] = Me.cmbReviewer

The problem now is in the Load Event of the other form. This one is not
working as I expected it to. It suppose to disable any control that don't
have a value but it just disables every thing. Any ideas?
Thank.
Ayo

Private Sub Form_Load()
If IsNull(Me.txtVendor.Value) Then
Me.txtVendor.Enabled = False
End If
If IsNull(Me.txtReviewer.Value) Then
Me.txtReviewer.Enabled = False
End If
If IsNull(Me.txtBeginDateRange.Value) Then
Me.txtBeginDateRange.Enabled = False
'Me.lblSDR.Enabled = False
End If
If IsNull(Me.txtEndDateRange.Value) Then
Me.txtEndDateRange.Enabled = False
'Me.lblEDR.Enabled = False
End If
If IsNull(Me.txtSingleDate.Value) Then
Me.txtSingleDate.Enabled = False
'me.lblSingleDate.Enabled = False
End If

End Sub
John W. Vinson said:
Sorry about that. What I meant to write was:
Call DoCmd.OpenForm("Form2")

Again: no Call is needed. DoCmd is a statement in its own right; you don't
"Call" it, just put

DoCmd.OpenForm("Form2").
Forms![Form2]![txtBox1]=Me("txtBox1")
Forms![Form2]![txtBox2]=Me("txtBox2")
Forms![Form2]![txtBox3]=Me("txtBox3")
Forms![Form2]![txtBox4]=Me("txtBox4")

The proper syntax would be

Forms![Form2]![txtBox4]=Me!txtBox4

though the parenthesis notation might be acceptable.
I want to use it for multiple entries

Well... you almost surely DON'T.

The only reason I can think of to do this is to copy data from Form1's
Recordsource into another table (Form2's Recordsource), storing a redundant
duplicate copy of the data.

It's almost never a good idea to do so; and - if you DO need to do so - it's
much better not to get Forms involved at all, but instead run an Append query
to append one or more records from the first table directly into the second
table.

What's the purpose of this exercise? What are you trying to accomplish?

John W. Vinson [MVP]
 
Top