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!

Auto populate form field

Status
Not open for further replies.

grendal

MIS
Sep 30, 2001
35
0
0
GB
I've two forms, Call Details and New Customer. Both forms have a Call Number field. The Call Details form has a command button which opens up the New Customer form. The On Click event for this command button reads:-

call number=FORMS!call details!call number

When I click on the command button I receive the following dialog:-

Microsoft Access can't find macro 'call number=FORMS!call details!call number'

I'm not sure where to go next!

Cheers s-)
Does the body rule the mind or does the mind rule the body - I dunno!
 
me![call number]=FORMS![call details]![call number]
Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
Thanks for prompt reply, however I'm still having the same dialog message but with me![call number]=FORMS![call details]![call number] included instead. Cheers s-)
Does the body rule the mind or does the mind rule the body - I dunno!
 
let me just ask the wwhole code you have in that on click event from private sub to end sub
and what is the code

call number=FORMS!call details!call number

supossed to do

i guess it should copy call number from call details into new customer

Christiaan Baes
Belgium
"What a wonderfull world" - Louis armstrong
 
I think your question has identified my problem. I dont understand your terms private sub and end sub .

On the command button properties I entered the code straight into the On click field.

Seems I've missed out a step! Cheers s-)
Does the body rule the mind or does the mind rule the body - I dunno!
 
Your code needs to go into the form's Module.

Click on the '...' next to the On Click properties field. When the dialog pops up, select Code Builder. You will be presented with the form's module. You'll see 'Private Sub YourButtonName_Click()' and 'End Sub'. The code that you want to execute (see Chrissie's post) goes between those two lines.

When set up properly, you'll notice that the On Click field in the form's Properties Box now says '[Event Procedure]". - - - -

Bryan
 
Thanks, for the above.

However I'm now receiving the following error "You can't assign a value to this object".

If it helps I've included the code below!

Private Sub New_Customer_Click()
On Error GoTo Err_New_Customer_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "New Customer Form"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Me![call number] = Forms![call form]![call details]![call number]

Exit_New_Customer_Click:
Exit Sub

Err_New_Customer_Click:
MsgBox Err.Description
Resume Exit_New_Customer_Click

End Sub

Any thoughts? Cheers s-)
Does the body rule the mind or does the mind rule the body - I dunno!
 
Too many parameters here, I think:

Me![call number] = Forms![call form]![call details]![call number]

What is the name of the form you are opening the new form from? Either 'call form' or 'call details' should not be in this line. - - - -

Bryan
 
The form I'm opening the new form from, is called 'call form' which has a subform called 'call details'. The 'call number' field is held within the subform. Cheers s-)
Does the body rule the mind or does the mind rule the body - I dunno!
 
Ok . . I'm a little confused about what you're trying to do.

What exactly do you want to happen when you open the New Customer form. i.e. what do you want linked??? - - - -

Bryan
 
OK, I've a form called 'call form'. This contains static customer account details such as name, address etc. Within this form there is a subform called 'call details' which contains the details of calls logged against each customer account. Each call has a unique log number.

I've created an open form command button on the subform. This opens a 'new customer account' request form. I need this form to have its 'call number' field auto filled from the 'call details' form, 'call number' field.

I hope this make sense! Cheers s-)
Does the body rule the mind or does the mind rule the body - I dunno!
 
Got it . .

'call form' and 'call details' are linked (the parent/child relationship) by the 'call number' field, right? - - - -

Bryan
 
No, there linked by the customer account number. The 'call number' is an auto number within the 'call detail' form. Cheers s-)
Does the body rule the mind or does the mind rule the body - I dunno!
 
Ok, so if I understand you right, you want to open the new form and pick up the 'call number' field (which is not the foreign key) from the 'call details' subform.

Let me just say at this point that I'm not sure you are going about this properly, design wise . .but I don't know enough about what you are doing to be sure.

It seems to be that typically, you will have your main form open and populated with data from an existing customer, with the subform populated from that existing customer. You then want to open a new customer form and populate that form with the data you pick up from an existing customer's subform???

I've never done this linking from a subform . .typically, this technique is used to open a form to add additional data to the many side of the relationship, and the new form is typically linked to the primary key of the main form.

However, try the following . .syntax wise it should be ok, but I'm not sure about the linking to the subform part:

- - -
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "New Customer Form"
stLinkCriteria = "[Call Number]=" & "'" & Forms!Call Details![Call Number] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria

- - -
The On Load event of 'New Customer Form' needs:

- - -
Forms!New Customer Form.Call Number = Forms!Call Details.Call Number
- - - - - - -

Bryan
 
Hi Bryan, when I've added your code, I receive a compile error on line 4.

On your earlier point, er, maybe I am tackling this in an over the top way. Short term I'll use another method I've been playing with, as I need to complete this today. Long term, I'll continue with the direction you've pointed me in - should be a head twister.

Thanks for your patience and help.
Cheers s-)
Does the body rule the mind or does the mind rule the body - I dunno!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top