use button to open form and load customer details from intial form?

Celtlink

Registered User.
Local time
Today, 00:24
Joined
Oct 21, 2010
Messages
10
Hi,

I need help especially reading forum answers for this type of question and still cannot do it.

I have the first form open "Form_Customer" with a button on it called "Create Order".
when I click on the button I want to open the "Form_Orders" form. (this I managed.)
On opening the Form_Orders I require the [Title] , [CName], [Address] , [Postcode] from the first form to autoappear in the orders form. The table names are the same in both forms.

On Form_Customer In the Click() for Create order button, I have the following code:

Private Sub CreateOrder_Click()
DoCmd.OpenForm Form_Orders, , , , acFormAdd, , Me.Title & "$" & Me.CName
End Sub

In load of Form_Orders I have:

Private Sub Form_Load()

If Me.NewRecord Then
Me.Title = Split(Me.OpenArgs, "$")(0)
Me.CName = Split(Me.OpenArgs, "$")(1)
End If

End Sub

Can anyone please advise why does this not work.... On another post this code was there and the guy said it worked. ?? I do not understand the programming at all really....so no comprehension of why it doesn't work....

Many thanks
Brian :(
 
An easier way to do this is use the the following on the on load event of the orders form

Code:
Me.Title = Forms("Form_Customer")("Title")
repeat for the fields you want to populate on the orders form with the controls on the customer form.
 
Thank You David,

I now get a debug error on the DoCmd line in the Form_Customer ?


Private Sub CreateOrder_Click()

DoCmd.OpenForm DocName, , , , acFormAdd, , Me.Title & "$" & Me.CName


End Sub

sorry for being so stupid....

thanks
Brian
 
sorry line stopping is :


DoCmd.OpenForm Form_Orders, , , , acFormAdd, , Me.Title & "$" & Me.CName
 
Last edited:
Where are you putting the code?
Is it in the DocName Form?

What error are you getting?
 
the DoCmdOpen am putting this in the Form_Customer form in the button for Click
 
the error is:
An Expression you enabled is wrong data type for one of the arguments
 
This code belongs on the OnClick event of the command button

Code:
DoCmd.OpenForm Form_Orders, , , , acFormAdd, , Me.Title & "$" & Me.CName

This code belongs in the On Load Event of the form being opened by the above code.

Code:
Me.Title = Forms("Form_Customer")("Title")
 
Hi David,

i have checked and even pasted in your code and all is correct places, but still have same error on click command in Form_Customer for CreateOrder Button Click()

The Debugger highlights the following line in Yellow:
DoCmd.OpenForm Form_Orders, , , , acFormAdd, , Me.Title & "$" & Me.CNameand states the following error:
An Expression you enabled is wrong data type for one of the arguments

I do not understand why this doesn't work, mainly coz am useless at code, but everything appears to be correct ?

cheers
Brian
 
Hi David,

i have checked and even pasted in your code and all is correct places, but still have same error on click command in Form_Customer for CreateOrder Button Click()

The Debugger highlights the following line in Yellow:
DoCmd.OpenForm Form_Orders, , , , acFormAdd, , Me.Title & "$" & Me.CNameand states the following error:
An Expression you enabled is wrong data type for one of the arguments

I do not understand why this doesn't work, mainly coz am useless at code, but everything appears to be correct ?

cheers
Brian

You need to encapsulate the name of the form in quotes (so if the form name is really Form_Orders then it would be):

Code:
DoCmd.OpenForm [B][SIZE=3][COLOR=red]"[/COLOR][/SIZE][/B]Form_Orders[B][SIZE=3][COLOR=red]"[/COLOR][/SIZE][/B], , , , acFormAdd, , Me.Title & "$" & Me.CName
And it is probably good to not name the form with this prefix Form_ because that has meaning to Access.
 
Hello David, Bob,

Extreme thanks to you both for helping me understand this problem !

Fantastic news - IT WORKS !!! :D

Great stuff cheers guys

Bnan
 

Users who are viewing this thread

Back
Top Bottom