Forms and passing data

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I have a form that has a button on it that opens another form, which you
can then add data about the first form...for example...
A form that pulls information from the Company table
the button opens
A form that pulls information from the contact table *specifically* for that
company

The company name is NOT repeated in the second form, but it is there in an
invisible field.

My question is, when I want to add a new contact for the company and I use
this form, it is not automatically putting in the company name. Is there a
way for me to automatically pass this information on to new entries? I know
I can do it if I have subforms, but I have too many different sections of
information to have all on one form (with or without subforms).

This probably is not very clear, but I'm not sure how to make it clearer.
Sometimes I feel like the two years of database classes I took don't help me
at all.

Thank you!
 
If you are using ac2k+ then you can use the OpenArgs argument of the OpenForm
command to pass any number of pieces of data.
 
I have access 2007. Can you please tell me how to use the OpenArgs? Is it
something I would use in a Macro? Because that, at least, I know how to do!!
 
Hi Sarah,
I'm afraid you will have to drop into code for a bit but it is pretty simple.
The code behind the button that opens the "OtherForm" probably looks like:

-----------------------------------------
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmOtherForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
-----------------------------------------

...you need to change it so it looks like:
----------------------------------------
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmOtherForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog, Me.txtCustomerName
----------------------------------------
...using *your* Form and Control names of course.

Now in the OnLoad event of the "frmOtherForm" you need to add the following
code:
---------------------------------------
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
'-- Form is being opened from a form passing the Customer name
Me.txtCustomerName = Me.OpenArgs
End If

End Sub
--------------------------------------

...again, using your txtCustomerName control name.

You build code by goint to the Event tab of the property sheet for the
control or form and pressing the elipsis "..." button and selecting Build
Code.

Post back if you need additional guidance.


I have access 2007. Can you please tell me how to use the OpenArgs? Is it
something I would use in a Macro? Because that, at least, I know how to do!!
If you are using ac2k+ then you can use the OpenArgs argument of the OpenForm
command to pass any number of pieces of data.
[quoted text clipped - 20 lines]
 
Hi,
Im beginner in access and I have a similar problem as Sarah. My first form
need to save the data of the customer in table Customer and automatically
send the customerID to second form. I will choose the room for the customer
and save it together with customerID at table Registration. Can I use the
above OpenArgs also?
Or there is anything else that I need to add?
I really appreciate any helps. thanks.

ruralguy via AccessMonster.com said:
Hi Sarah,
I'm afraid you will have to drop into code for a bit but it is pretty simple.
The code behind the button that opens the "OtherForm" probably looks like:

-----------------------------------------
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmOtherForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria
-----------------------------------------

...you need to change it so it looks like:
----------------------------------------
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmOtherForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog, Me.txtCustomerName
----------------------------------------
...using *your* Form and Control names of course.

Now in the OnLoad event of the "frmOtherForm" you need to add the following
code:
---------------------------------------
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
'-- Form is being opened from a form passing the Customer name
Me.txtCustomerName = Me.OpenArgs
End If

End Sub
--------------------------------------

...again, using your txtCustomerName control name.

You build code by goint to the Event tab of the property sheet for the
control or form and pressing the elipsis "..." button and selecting Build
Code.

Post back if you need additional guidance.


I have access 2007. Can you please tell me how to use the OpenArgs? Is it
something I would use in a Macro? Because that, at least, I know how to do!!
If you are using ac2k+ then you can use the OpenArgs argument of the OpenForm
command to pass any number of pieces of data.
[quoted text clipped - 20 lines]
Thank you!

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
The OpenArgs will work here also. Saving the record includes:

DoCmd.RunCommand acCmdSaveRecord
Hi,
Im beginner in access and I have a similar problem as Sarah. My first form
need to save the data of the customer in table Customer and automatically
send the customerID to second form. I will choose the room for the customer
and save it together with customerID at table Registration. Can I use the
above OpenArgs also?
Or there is anything else that I need to add?
I really appreciate any helps. thanks.
Hi Sarah,
I'm afraid you will have to drop into code for a bit but it is pretty simple.
[quoted text clipped - 45 lines]
 
Thank you a lot..It's working greatly.

ruralguy via AccessMonster.com said:
The OpenArgs will work here also. Saving the record includes:

DoCmd.RunCommand acCmdSaveRecord
Hi,
Im beginner in access and I have a similar problem as Sarah. My first form
need to save the data of the customer in table Customer and automatically
send the customerID to second form. I will choose the room for the customer
and save it together with customerID at table Registration. Can I use the
above OpenArgs also?
Or there is anything else that I need to add?
I really appreciate any helps. thanks.
Hi Sarah,
I'm afraid you will have to drop into code for a bit but it is pretty simple.
[quoted text clipped - 45 lines]
Thank you!

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
Another question..how can I pass up more than one field to the second form. I
mean not only CustomerID but maybe name and gender also. It just to view in
second form but just CustomerID will be saved in second form.
Is it something that I must add at the code?

ruralguy via AccessMonster.com said:
You are very welcome. Glad I could help.
Thank you a lot..It's working greatly.
The OpenArgs will work here also. Saving the record includes:
[quoted text clipped - 14 lines]
Thank you!

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
You can concantenate all of your passed parameters in the OpenArgs string
separated by a common character like the semicolon ";".

Dim MyOpenArgs As String

MyOpenArgs = Me.txtCustomerID & ";" & Me.txtGender & ";" & Me.txtPhone

Then use the Split() function in the next form to break them apart into an
array.

Dim Args As Variant
If Not IsNull(Me.OpenArgs) Then
Args = Split(Me.OpenArgs, ";")
Me.txtCustomerID = Args(0)
Me.txtGender = Args(1)
Me.txtPhone = Args(2)
End If
Another question..how can I pass up more than one field to the second form. I
mean not only CustomerID but maybe name and gender also. It just to view in
second form but just CustomerID will be saved in second form.
Is it something that I must add at the code?
You are very welcome. Glad I could help.
[quoted text clipped - 5 lines]
 
Oh, is that mean i need to change my code at first form's button which is :
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog, Me.txtCustomerName
to this:
Dim MyOpenArgs As String
MyOpenArgs = Me.txtCustomerID & ";" & Me.txtGender & ";" & Me.txtPhone

So, I dont need to use stDocName and stLinkCriteria ? Tell me if I wrong.

ruralguy via AccessMonster.com said:
You can concantenate all of your passed parameters in the OpenArgs string
separated by a common character like the semicolon ";".

Dim MyOpenArgs As String

MyOpenArgs = Me.txtCustomerID & ";" & Me.txtGender & ";" & Me.txtPhone

Then use the Split() function in the next form to break them apart into an
array.

Dim Args As Variant
If Not IsNull(Me.OpenArgs) Then
Args = Split(Me.OpenArgs, ";")
Me.txtCustomerID = Args(0)
Me.txtGender = Args(1)
Me.txtPhone = Args(2)
End If
Another question..how can I pass up more than one field to the second form. I
mean not only CustomerID but maybe name and gender also. It just to view in
second form but just CustomerID will be saved in second form.
Is it something that I must add at the code?
You are very welcome. Glad I could help.
[quoted text clipped - 5 lines]
Thank you!

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
Dim MyOpenArgs As String
MyOpenArgs = Me.txtCustomerID & ";" & Me.txtGender & ";" & Me.txtPhone
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog, MyOpenArgs
Oh, is that mean i need to change my code at first form's button which is :
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog, Me.txtCustomerName
to this:
Dim MyOpenArgs As String
MyOpenArgs = Me.txtCustomerID & ";" & Me.txtGender & ";" & Me.txtPhone

So, I dont need to use stDocName and stLinkCriteria ? Tell me if I wrong.
You can concantenate all of your passed parameters in the OpenArgs string
separated by a common character like the semicolon ";".
[quoted text clipped - 24 lines]
 
Thanks again.It's working.Thanks for your time.I've learned a lot today.

ruralguy via AccessMonster.com said:
Dim MyOpenArgs As String
MyOpenArgs = Me.txtCustomerID & ";" & Me.txtGender & ";" & Me.txtPhone
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog, MyOpenArgs
Oh, is that mean i need to change my code at first form's button which is :
DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog, Me.txtCustomerName
to this:
Dim MyOpenArgs As String
MyOpenArgs = Me.txtCustomerID & ";" & Me.txtGender & ";" & Me.txtPhone

So, I dont need to use stDocName and stLinkCriteria ? Tell me if I wrong.
You can concantenate all of your passed parameters in the OpenArgs string
separated by a common character like the semicolon ";".
[quoted text clipped - 24 lines]
Thank you!

--
HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
Outstanding! Glad you got it working.
Thanks again.It's working.Thanks for your time.I've learned a lot today.
Dim MyOpenArgs As String
MyOpenArgs = Me.txtCustomerID & ";" & Me.txtGender & ";" & Me.txtPhone
[quoted text clipped - 13 lines]
 
Hi again, it's been a while..
I've got another question..
Can I use this openargs to passing data to another form when I double
clicked the list box ?
Thanks.


ruralguy via AccessMonster.com said:
Outstanding! Glad you got it working.
Thanks again.It's working.Thanks for your time.I've learned a lot today.
Dim MyOpenArgs As String
MyOpenArgs = Me.txtCustomerID & ";" & Me.txtGender & ";" & Me.txtPhone
[quoted text clipped - 13 lines]
Thank you!
 
You can use the OpenArgs argument any time you use the OpenForm or OpenReport
commands.
Hi again, it's been a while..
I've got another question..
Can I use this openargs to passing data to another form when I double
clicked the list box ?
Thanks.
Outstanding! Glad you got it working.
[quoted text clipped - 5 lines]
 
Back
Top