Access 2002

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

Guest

Hello,

I am new to the Access Object Model and I am trying to move some macros that
I have to VBA code. Can anyone please help me out by indicating how can I
access the value of a field from several tables. I think I can preatty much
figure out how to calculate those values but I am having a hard time finding
anything with just the info that I need to access those values. Any help
would be greatly appreciated.

In advance thanks,

uGek
 
I guess the question is "where" and when do you need those values.

If you go a form based on several tables (either by sub-forms, or by a sql
relational join), then you can reference the controls, or recordset of that
form directly.

I mean, when you say reference a value, what value do you want, and when?

You can use the dlookup command to grab a value.

dlookup("what field", "what table", "conditions")
Lets say I ask you for the key id of a company record, and then want to
display the company name, I could go:

dim strID as string
dim strCompnay as string
strID = inputbox("what company id to fetch")

if strID <> "" then

strCompany = dlookup("CompanyName","tblCustomers","id = " & strID)

msgbox "the company name is " & strCompany

end f

On the other hand, if you go a form with the company name already deployed,
then

msgbox "the company name is " & me!CompanyName

So, that is why I asked where, what, when etc. you want to display this
information.

For the most part, to display other values from other tables, you don't need
code, but the correct control on a form (ie: a sub-form, or a control with a
dlookup).

It is possible that you need to retrieve all values from that other table.

dim strSql as string
dim rstReocrd as dao.RecordSet

strSql = "select * from tblCustomers where id = 123"
set rstRecord = currentdb.OpenRecordSet(strSql)

now, we can go:

msgbox "company name is " & rstReocrd!CompanyName
msgbox "last name is " & rstRecord!LastName

So, you can pull a whole record into a recordset, and then examine it.

So, a recordset is a good way when you need to do some "data" processing.
 
Back
Top