Results 1 to 9 of 9
  1. #1
    cassidym is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44

    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

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    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.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cassidym is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    Thanks. I'll try the brackets. If that doesn't work, I'll try renaming the field. Not familiar with conditional formatting.

  4. #4
    cassidym is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    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

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Try

    If Me.Category = "Contractor" Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    cassidym is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    Thanks, I'll try the quotes

    Mike C

  7. #7
    cassidym is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    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?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    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?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    cassidym is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    44
    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.

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums