Access 2007: I want fields to self-populate on the click of a butt

C

Courtney G

Hello.

I am designing a 'Customer Projects' form which has 6 fields for the project
address. 'Customer Projects' are related to 'Customers'. In the 'Customers'
table and form there are also 6 fields for an address - described as the
postal address.

Sometimes the project address and the postal address are the same.
Sometimes they are not. I would like to create a button on the 'Customer
Projects' form that says 'Same as postal address'. I would like users to be
able to click on it and for the fields to then self-populate with the
customer's postal address.

One stipulation is that I do not want the project address to change if, for
example, the customer moves house and their postal address changes.

Can any of you whizzes help me please??

CHEERS!
 
A

Albert D. Kallal

The code behind the buttion would look like:

Dim rstCust As DAO.Recordset
Dim strSql As String

strSql = "select * from tblCustomers where id = " & Me!customer_id
Set rstCust = CurrentDb.OpenRecordset(strSql)

Me.ADDRESS = rstCust!ADDRESS
Me.CITY = rstCust!CITY
Me.State = rstCust!State
Me.ZipCode = rstCust!ZipCode
rst.Close


in the above, customer_id is the forighn key collum used to relate back to
the customers table.
 
C

Courtney G

Thank you for your advice. This is the first time I have tried to work with
code, so please bear with me.

I have edited the code as far as I can see I need to due to my field names
and table names which are as follows:

Customer projects table: tbl_Projects
Customer table: tbl_Enquiries

This is how I have edited your sample (below):

Private Sub Command106_Click()
Dim rstCust As DAO.Recordset
Dim strSql As String

strSql = "select * from tbl_Enquiries where id = " & Me!EnquiryID
Set rstCust = CurrentDb.OpenRecordset(strSql)

Me.ProjectAddressLine1 = rstCust!PostalAddressLine1
Me.ProjectAddressLine2 = rstCust!PostalAddressLine2
Me.ProjectAddressLine3 = rstCust!PostalAddressLine3
Me.ProjectCity_Town = rstCust!PostalCity
Me.ProjectCounty = rstCust!PostalCounty
Me.ProjectPostCode = rstCust!PostalPostcode
rst.Close


End Sub


Am I on the right track? It's not working for me as is. I am getting the
following message:

Run-time error '3061':
Too few parameters. Expected 1.


I really appreciate your help!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top