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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I check a field value not in form 1

Status
Not open for further replies.

Knutjo

Programmer
Jan 15, 2002
31
NO
I'm working on a Access/VBA program where I need/want to do check on a field not represented on the form. My code look like this:

If [Tablename].[FieldName] = "something" Then
....dosomething
End If

I get an error-message that says that field don't exist, but that not true. Tablename and Fieldname are correct spelled.

Is it possible to access [Tablename].[FieldName] directly ?
What's the correct syntax ?

Regards Knut
 
Two things wrong here...

1. Reference your form, not the table.

2. Check your RecordSource behind the form and make sure it includes the field you are searching on. Without it, it won't work. What I am not saying here is you need to place a control on the form with that ControlSource. However, it must be in your RecordSource property of the form.

Example:

Illustration...
Me.RecordSource = "SELECT MyField FROM MyTable;"

How to reference it...
Me![MyField]

If its a field on another form entirely...

Forms("MyOtherForm").MyField

Referencing the table won't work, because first, it is not an open object, the form is. Second, referencing the way you were attempting provides no way of accessing the data in that table. Only the field characteristics of that TableDef object.

I hope I did not misunderstand your question. I hope that helps.

Gary
gwinn7


 
Knut,

Check out Access help for the DLookup function. You can use the DLookup function to display the value of a field that isn't in the record source for your form or report.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top