View Single Post
  #3  
Old November 19th, 2008, 01:17 PM posted to microsoft.public.access.tablesdbdesign
Allen Browne
external usenet poster
 
Posts: 11,706
Default Automatically filling fields with 'standing' data

So you have tables like this:
- The Client table holds one address for each company.
- The Contact table holds one address for each contact.
- The Contact table has a ClientID foreign key field, so any conctact can be
associated with just one company.

The Contact may need to have an address that's different than their company
address, but you want it to default to the same company whenever you set the
ClientID field for the contact.

If that's the story, use the AfterUpdate event procedure of the ClientID
combo box on the contacts form, to assign the address. This kind of thing:

Private Sub ClientID_AfterUpdate()
Dim rs As DAO.Recordset
Dim strSql As String
If Not IsNull(Me.ClientID) Then
strSql = "SELECT Address, City, State, Zip FROM tblClient WHERE
ClientID = " & Me.ClientID & ";"
Set rs = dbEngine(0)(0).OpenRecordset(strSql)
If rs.RecordCount 0 Then
Me.Address = rs!Address
Me.City = rs!City
Me.State = rs!State
Me.Zip = rs!Zip
End if
rs.Close
Set rs = Nothing
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"JMGreen" wrote in message
...
I think this should be easy but cannot get my head round it.
I have a database that includes a table of clients and a table of
contacts.
Each contact is linked to one client.
When I input a new contact (John Smith say), into the contact table and
select from my pull down menu which client he is linked with (ABC Ltd,
say),
from the client table, I want the address and contact details of that
client
to automatically fill, in the John Smith contact form.

The relevant information resides in the Client table

I cannot seem to be able to make this link