Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with accesssing a table from a form

Status
Not open for further replies.

new57

Programmer
Nov 3, 2001
17
US
i am trying to get a row from a "table b" based on a value from a field from "form a/table a".

i am trying to execute the code from a click event.

i have tried the docmd and recordset and macros,

but i cannot get the value from table b into the field in form a.

what am i missing, it must be so obvious i cant see it.

thanks
 
If we are dealing with two forms then this code should work on a button named Details. This is for Fields with Text.


On Error GoTo Err_Details_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormName"

stLinkCriteria = "[LinkField]=" & "'" & Me![LinkSource] & "'"
Screen.PreviousControl.SetFocus
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Details_Click:
Exit Sub

Err_Details_Click:
MsgBox Err.Description
Resume Exit_Details_Click

For a numeric field substitute this


stLinkCriteria = "[LinkField]=" & Me![LinkSource]

If you are opening a query then in the Criteria you could put

Forms!FormName!LinkSource

You will have to substitute your Form, Table and Field Names. Sandy
 
Try using this code:
DLookUp(FieldName, TableName, "Criteria")


Example: Looks up the first name of the person whose customer ID = 5 in the Customers table

FN=dlookup("FirstName","tblCustomers","CustomerID=5")

Pat B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top