I have two tables: Organisations & Invoices. I have a form called Invoices that is used to enter data into the invoices Table. When entering data, I'd like to be able to type into the [Organisation Code] field, and then click on the ! button to run an SQL script....which will populate some of the fields on the form. Having read discussions here, I've tried some scripting but it does not work. Not sure if I'm on the right track even. Can you help?
Code:
Private Sub LoadInfo_Click()
' Pull info out of SQL View.
Dim db As Database
Dim rs As Recordset
Dim tmpUser As String
Set db = Organisations
Set rs = db.OpenRecordset("Select * FROM dbo_Organisations WHERE [Organisation Code] = '" & Organisations.[Organisation Code] & "'")
Invoices![Organisation Type] = rs![Organisation Type]
Invoices!Organisation = rs!Organisation
Invoices![Organisation Phone] = rs![Organisation Phone]
Invoices![Organisation Fax] = rs![Organisation Fax]
Invoices!Department = rs!Department
Invoices!Street = rs!Street
Invoices!Suburb = rs!Suburb
Invoices!State = rs!State
Invoices!Country = rs!Country
Invoices![Contact Title] = rs![Contact Title]
Invoices![Contact First Name] = rs![Contact First Name]
Invoices![Contact Surname] = rs![Contact Surname]
Invoices![Contact Position] = rs![Contact Position]
Invoices![Contact MOB] = rs![Contact MOB]
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Comment