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

Code Question

Status
Not open for further replies.

kiefmer

MIS
May 19, 2000
66
US
I am new with VBA, so bear with me. I am doing an IF statement, and I wrote it like this:
if
![blahblah].[blah] = "1" then
me.blahblah.fontweight = normal
end if

now the reason why I put "table" in brackets is because I have done that with "Form". When I run the code I get an error
run-time error '2465'
Microsoft Access can't find the field '|' referred in your expression.

I have the code written exactly like you see (just without the blah's). Can someone give me some help on why this isn't working?

Thanks,
Heath
 
Heath,
If I understand you code, don't use the key word 'Table' in your code.

Example: Table: Employees, Field: Active

If [Employees].[Active] = -1 then 'For yes/no data type, can use -1 (yes), 0 (no) or True or False.
Me.name of text control.FontWeight = ....
End If

Hope this answers the question.

Jeff Logan
 
I tried it but it didn't work. Here is what I have:

Table: section1_form_t
Field: complete

If
![section1_form_t].[complete] = "1" then
me.server_hardware.fontweight = normal
end if

I tried taking the
out but I got the same error.

Any other ideas? I have multiple tables and the buttons that I am trying to get this to work on will have to reference different tables.

Heath
 
Hi kiefmer,

Where have you got this code? And what are you trying to reference?

Even if you get the syntax right, Table.Column will refer to the column itself not to the value of the contents of the column on a particular record.

If you are in code behind a form and you want to refer to a control on the form use Me!ControlName. If it's something/somewhere else please post back with more details.

Enjoy,
Tony
 
This is code that is behind a form. There are a couple of buttons on that form that are going to need to find out if the table that they are connected to has a '1' or a '0' in the field. If it has a '1' then it will make the font normal instead of bold.

Does this make more sense?
 
Hi kiefmer,

Just more questions, I'm afraid - I'm still not clear.

When you say table do you really mean record - the current record on the form perhaps. Or are you trying to reference data that is not attached to the form?

What is the relationship between the data on the form and the table(s) you are trying to read? If the field you want is in the form's recordset you can reference it with the Me qualifier (Me![complete] for example) whether or not it is actually a control on the form. If the field you want is not in the form's recordset you need something completely different.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top