Tables and Forms.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In Access2000 is it possible to refer to a field in a table from a form with
which it is not linked. For example I have tables Tab1 and Tab2 and I have a
form frmMain and its Record Source property is set to Tab1. Can I access a
record from Tab2 onto a textbox on frmMain.

Thanks
 
Farooq,

You have a couple of options:

1. Using DLookup()
Me!txtMyTextbox = DLookup("[myfield]", "Tab2", "field1 = 123")

the "field = 123" part means "WHERE field = 123"

2. Using a recordset
Dim db As Database
Dim rs As DAO.Recordset
Dim sSQL As String

Set db = CurentDb
sSQL = "SELECT myfield FROM Tab2 WHERE field = 123"
Set rs = db.OpenRecordset(sSQL, dbOpenSnapshot)
If rs.AbsolutePosition > -1 Then
Me!txtMyTextBox = rs!myfield
End If

rs.Close
Set rs = Nothing
Set db = Nothing

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Back
Top