Autopopulate form from different source help

  • Thread starter Thread starter jimcrowley
  • Start date Start date
J

jimcrowley

Hi! I've been tasked with creating a quick form for a database that
will go away in three months or so. What I want to do is:

1. On Form1 I want the user to enter data into Textbox1 which I have
bound to Table1.
2. I want to be able to check to see if the data entered in Textbox1
matches a a field in a record in Table2 and then update Textbox2,
Textbox3, etc with data from Table2.
3. If there is no record in Table2, then the user can enter data for
Textbox2, 3, 4, etc.
4. The user will also have to enter data in certain objects on the form
no matter what.

I realize that I should not house identical data in separate tables,
but this is temporary and I just need to get it done.

I'm not much of a programmer, but I am indeed stuck.

Could a kind soul (or even an unkind one?) please point me in the right
direction?

Thanks,
JC
 
Jim,

Here is some quick "air code", for the After Update event of Textbox1,
that might get you going....

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT * FROM Table2 WHERE Field1
='" & Me.Textbox1 & "'")
If rst.RecordCount Then
Me.Textbox2 = rst!Field2
Me.Textbox3 = rst!Field3
Else
MsgBox "No matching record in Table2"
End If
rst.Close
Set rst = Nothing
 
you can accomplished this by using VBA.
Try to use this code as your reference.

Private Sub textbox1_lostFocus()
Dim rs as ADODB.Recordset
set rs = new ADODB.Recordset
rs.Open "Select*From Table2 where Field = " & textbox1,
currentproject.connection,adOpenStatic,
adLockOptimistic
if rs.RecordCount > 0 then
textbox2 = rs!Field2
textbox3 = rs!Field3
end if
End sub
 
Back
Top