-
VB Question
Got a Personnel DB and my user wants the employee's name to be in green in the report if he's a contractor and black if he's a sub-contractor. In the Table, I have a field NAME and a field Category. The Category field lets you select Contractor or Sub-Contractor. So I wrote the VB as follows:
If Me.Category = Sub-Contractor Then
Me.Name.ForeColor = vbGreen Else
Me.Name.ForeColor = vbBlack
EndIf
But when I try to complie this is get a Compile Error Message stating that NAME is an invalid qualifier.
Would appreciate any advice.
Thanks
-
That is because "Name" is a reserved word (Access thinks you're trying to refer to the name of the form/report there). You should change the field name, but you can try bracketing it.
You might also look at Conditional Formatting, which is generally an easier way to accomplish this type of thing.
-
Thanks. I'll try the brackets. If that doesn't work, I'll try renaming the field. Not familiar with conditional formatting.
-
Tried this and it compiled okay but the Employee name didn't change color. Here's what I did:
-Double clicked on the Details bar
- Clicked on the Event tab and clicked on Format and chose Code Builder
- Then wrote the following:
If Me.Category = Contractor Then
Me.Employee.ForeColor = vbBlue
Else: Me.Employee.ForeColor = vbGreen
As I said, it does compile but the letters don't change color.
Would appreciate any help
Thanks
-
Try
If Me.Category = "Contractor" Then
-
Thanks, I'll try the quotes
Mike C
-
Apparently the problem was that I was working in Access 07. When I switched computeres and tried the vb in Access 03, it worked fine. But the same code in 07 didn't. Interestingly enough, I was able to email the working 03 file to the computer with 07 on it and it worked fine. There must be some difference between 03 and 07 vb. Any thoughts?
-
Well, there's nothing there that shouldn't work in either. One guess would be that the database wasn't in a trusted location, in which case no code would run at all. Is that a possibility?
-
I stored the DB I developed in 03 and emailed to myself on the computer that's running 07 and it works fine. But the code I wrote in the 07 version, won't run. They are stored in the same folder.
Go figure.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules