Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form to Form autofill??How? 2

Status
Not open for further replies.

435

Technical User
Jul 22, 2003
24
0
0
US
I made two forms EMPLOYEE form wich has the a box to
fill in a user#, and then theres a button that takes
the user to the next form(CUSTOMER). In the customer form
for now i have the following fields, Name, Last Name and
the the user# wich is the same as the EMPLOYEE form.

What i wan to know is what code to use or how to make
the button send the information, the user# into the
next form on the same name field user#.

Any help is greately apreciated.
 
You should read the Access help file for the 'OpenForm' method and the OpenArg property. You will see that the last argument in the OpenForm method argument list is 'OpenArgs': DoCmd.OpenForm formname[, view][, filtername][, wherecondition][, datamode][, windowmode][, openargs]

If you insert the User# from your Employees form into this argument position it will be passed to the Customers form as it's OpenArg value. You can easily transfer this data into the User# field on the Customers form using the form's Open event.

For example, assuming the User# textbox on the Employees and Customers forms are called txtUser then...

In the Click event for the button that opens the Customers form use:

Dim stOpenArg as Variant
stOpenArg = txtUser
Docmd.OpenForm "CUSTOMERS",,,,,,stOpenArg

Using a Variant variable ensures that a null value doesn't cause an error should you click the button before entering a User# in the field.

In the Open event for the Customers form use:

txtUser = OpenArgs


This will update the form's User# field as required.
 
I did what you told me TUNSAROD
but for some reason im getting a debug
error. "You can't assign a value to this object"
I click debug and I get a highlight on txtUser = OpenArgs

((((((((((((((THIS IS THE CUSTOMER FORM CODE)))))))))))))))
Private Sub Form_Open(Cancel As Integer)
-->txtUser = OpenArgs
End Sub
((((((((((((((((((((((((((((((()))))))))))))))))))))))

)))))))))))))THIS IS THE EMPLOYEE FORM CODE((((((((((((((((((
Private Sub Command6_Click()
Dim stOpenArg As Variant
stOpenArg = txtUser
DoCmd.OpenForm "CUSTOMER", , , , , , stOpenArg

End Sub
((((((((((((((((((((((((((())))))))))))))))))))))))))))))

Am I putting the code correctly??????

 
This is probably because the text-box on the CUSTOMERS form that you are trying to send the OpenArgs value to is already linked to a field in the CUSTOMERS table. The target text-box must be 'unbound'.

If you are trying to create a new record in CUSTOMERS where the UserID is added using this method then you might like to consider having the CUSTOMERS form unbound (not attached to a table) but after entering the data in the form run an UPDATE query to copy the form's data into the table as a record. Alternatively use the OpenRecordset method and the AddNew and Update methods to create a new table record.

Both these processed offer the great advantage that whilst entering data onto the CUSTOMERS form the record is not created until your code creates it. Whereas when a bound form is in data-entry mode the instant any data is entered into a text-box Access creates a record.

hth
Rod
 
Ok i did what you told me i made the text box unbound, i dont get any error now, but the box doesn't fill with the number from the previous form.

Is there a way to post the sample file that im working on
or do i have to email it ??? I would really apreciate it
if someone could give me a hand with this!

I'm trying to figure it out,,, im still trying1/!!
 
Hi 435

Sorry to ignore you I haven't been on-line for a few days.

Are you still having problems with this or are you over that hurdle?

In the assumption that you need more help I suggest that you start from scratch to create a working example that does nothing but this one thing.

1. create a form and name it: frmCUS

2. add a text box and name it: Text0

3. in the form's code window add:

Private Sub Form_Open(Cancel As Integer)
If Not IsNull(OpenArgs) Then
Text0 = OpenArgs
End If
End Sub

4. save the form and close it.



5. create another form and name it: frmEMP

6. add a text box named: Text0

7. with Wizards switched OFF add a command button and call it: cmdOpenCUS

8. in the Click event property for the new button select [Event Procedure] but don't click on the Build button.

9. open the form's code window and paste in the following code which is the bare minimum required to get this working..

Private Sub cmdOpenCUS_Click()
DoCmd.OpenForm "frmCUS", , , , , , Text0
End Sub


10. save the form and switch to form view.


Now enter some text into the text box on the frmEMP and click the button.

If you have followed these instructions you should see frmCUS open with the text from frmEMP in its text box.

Fingers crossed!

Let me know how this goes.
 
Thanks for the input i figured it out, you guys sure help a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top