Results 1 to 11 of 11
  1. #1
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156

    Trouble coding a color palette - "Compile error: Invalid outside procedure"

    Hi, y'all! I'm having some trouble with an Access project I'm doing for work, and would GREATLY appreciate some help. Please bear with me, as my grasp of technical terms is limited; I've only been working in Access for a couple of months now, and I've just started learning VBA (I'm in insurance, not IT; I think I was nominated for this project because I'm just stubborn enough to sit down with a pile of "for Dummies" books, and figure it out).



    I'm trying to set up the company/clients' color palette in my database so that I can use it for all forms and reports. To that end, I've made it a Standard Module. I'm following the guidance on pages 102 and 103 of "Access 2007 VBA Programming for Dummies", and input the code as shown on those pages (except, of course, with the colors that I need). The problem I'm running into is that now any time I try to use any other functions of the database that involve VBA (for example, trying to login), I get a "Compile error: Invalid Outside procedure" message, and the debugger pops up, highlighting the value for red in the first color (81). There's nowhere in the database that I've actually applied these colors yet, so I don't see how it should be communicating with anything. The only thing I can think of is that everywhere else I see VBA, there's clearly defined beginning and ending statements (End If, End Sub...), but there weren't for this one. Is that the problem?

    Code:
    Option Compare Database
     
     'Declare color names as Long Integer variables.
     
     'Primary Palette
    Dim HUBBlue As Long, HUBOrange As Long, HUBGreen As Long, HUBNavy As Long
     'Secondary Palette
    Dim HUBBlue1 As Long, HUBBlue2 As Long, HUBBlue3 As Long, HUBGrey As Long, HUBPurple As Long
    Dim HUBOrange1 As Long, HUBOrange2 As Long, HUBGreen1 As Long, HUBMaroon As Long
     'Financial Services Secondary Palette
    Dim HUBFGrey1 As Long, HUBFGrey2 As Long, HUBFGrey3 As Long, HUBFGrey4 As Long, HUBFBlack As Long
    Dim HUBFBlue1 As Long, HUBFBlue2 As Long, HUBFBlue3 As Long, HUBFBlue4 As Long, HUBFBlue5 As Long
     'Palette
    Dim IPRed As Long, IPBlue As Long
     'Palette
    Dim RRFRed As Long, RRFGreen As Long, RRFGrey As Long
     'Assign colors to variables as RGB values.
     
    HUBBlue = RGB(81, 145, 205)
    HUBOrange = RGB(208, 111, 26)
    HUBGreen = RGB(193, 175, 44)
    HUBNavy = RGB(36, 48, 58)
    HUBBlue1 = RGB(0, 82, 149)
    HUBBlue2 = RGB(86, 155, 190)
    HUBBlue3 = RGB(85, 188, 235)
    HUBGrey = RGB(99, 100, 102)
    HUBPurple = RGB(79, 38, 131)
    HUBOrange1 = RGB(231, 166, 20)
    HUBOrange2 = RGB(255, 196, 37)
    HUBGreen1 = RGB(76, 114, 29)
    HUBMaroon = RGB(130, 0, 36)
    HUBFGrey1 = RGB(226, 228, 230)
    HUBFGrey2 = RGB(172, 175, 178)
    HUBFGrey3 = RGB(118, 122, 126)
    HUBFGrey4 = RGB(64, 69, 74)
    HUBFBlack = RGB(37, 40, 42)
    HUBFBlue1 = RGB(172, 203, 231)
    HUBFBlue2 = RGB(135, 166, 194)
    HUBFBlue3 = RGB(86, 117, 145)
    HUBFBlue4 = RGB(49, 81, 109)
    HUBFBlue5 = RGB(24, 56, 84)
    IPRed = RGB(164, 16, 40)
    IPBlue = RGB(0, 38, 96)
    RRFRed = RGB(130, 0, 36)
    RRFGreen = RGB(0, 115, 88)
    RRFGrey = RGB(106, 115, 123)
    I removed some company info from the comments, but comments aside, this is exactly what's in the system. Can anyone see something I'm missing?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The code to set the variables is not within a Sub or Function procedure.

    If you want the variables to be available by any procedure in any module, they must be declared as global variables in the header of a general module. And might better declare them as constants. Variables will lose their value if code execution is interrupted. Constants will not.

    Review http://www.access-programmers.co.uk/...d.php?t=138975

    If you want to get really adventurous, another option is TempVars - they don't lose their value if code execution is interrupted. I've never used them.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156
    Thanks so much! That sounds like it'll solve my problem. Your mention of TempVars has intrigued me, though...I may have to research that first. Darn my curiosity!

  4. #4
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156
    Please pardon my ignorance, but I'm still not able to get my color palette working. I've tried different formats--including the one in the link--when I've had time the last couple of days, and I just keep getting errors. The closest I got to success was making one of my forms turn black when clicked, but it was supposed to be one of the blue shades.

    Sorry, my experience with VBA consists of: I've read 137 pages into the "For Dummies" book so far, and found a few codes (like to create a login page, and popup calendars) online that I was able to tweak into working for my projects.

    I did go back in the book and try to set them up as Constants according to the instructions there, but I couldn't get that to work, either. I am so lost right now.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I don't want to build just to test and try to replicate issue. If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156
    Oh! That makes sense. Sorry, still VERY new to this.

    Please don't laugh at it.

    Account Management Database (OFFLINE)_2014-08-08_2014-09-03 - Copy.zip

    I DID manage to get the colors in as variables, but I'd really like to figure out how to get them to work as constants, like you'd said. Still can't get the color to apply anywhere. I know I am doing something horrifically wrong. Thank you SO MUCH for taking the time to look at this.

  7. #7
    Parsonshere is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2012
    Location
    Rusk
    Posts
    25
    I haven't looked at the database, but the original post looks like a function to me.
    Functions return a value which may be read into a variable.
    Since the RGB is a function itself that returns a long, that in turn may be used to populate a control's property for a color palette such as back color on the format tab of a form's property dialog, you may try something like:
    Sub tryit()
    Dim x
    x = SetIt("HUBGrey")
    MsgBox x
    End Sub
    Function SetIt(xColor As String) As Long
    Select Case xColor
    Case "HUBGrey"
    SetIt = RGB(99, 100, 102)
    Case "HUBPurple"
    SetIt = RGB(79, 38, 131)
    Case "HUBOrange1"
    SetIt = RGB(231, 166, 20)
    End Select
    End Function

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I can't get variables to work either. But I can get constants to work.

    In the header of HUBPaletteColorModule:

    Option Compare Database
    Public Const myYellow As Long = vbYellow
    Public Const myLtGray As Long = &HCCFFFF

    Then in the Login form Load event:

    Private Sub Form_Load()
    Me.ID.BackColor = myYellow
    Me.Password.BackColor = myLtGray
    End Sub

    Could not get RGB(x, y, z) to work in the constant declarations.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    IncidentalProgrammer is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2014
    Location
    Texas
    Posts
    156
    Thanks! I'm trying out both methods.

    June7, the "&HCCFFFF" for LtGray; what are those letters? I've seen colors expressed like that one other time, but I couldn't find information on what that is, and how to translate it. Is that a replacement for RGB? And if so, is there a dictionary or list that gives the values?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Those are hex values.

    Bing: Access color codes

    Here's one http://www.cloford.com/resources/colours/500col.htm

    and http://office.microsoft.com/en-us/ac...080755535.aspx

    Note the example code used &H in place of #.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    Parsonshere is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2012
    Location
    Rusk
    Posts
    25
    To demo.
    In design mode, Put a command button on your form.
    Name the control: cmdChgDetailColor
    From the properties dialog for the control, in the event, Select "Event Procedure"
    Click the ellipses, and paste the code between sub and end sub statements (those will have already been created)
    paste the above function into a module in the same database.

    Private Sub cmdChgDetailColor_Click()
    With Me.Detail
    If .BackColor = 1353447 Then 'it's purple
    .BackColor = modFun.SetIt("HUBPurple")
    Else
    .BackColor = modFun.SetIt("HUBOrange1")
    End If
    End With
    End Sub

    To see what has happened,
    Open you form in design mode
    Highlight or Select the detail section (It's a bar below the header of the form, and says "Detail" on it.
    Click the properties from the tools group while still in design mode.
    Click the format tab
    You will see one property (line )that says back color.
    You can select a color here that will put a number in this property. Your function is doing the same thing.

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

Similar Threads

  1. Replies: 5
    Last Post: 06-26-2013, 02:29 PM
  2. Replies: 4
    Last Post: 06-24-2013, 07:12 AM
  3. Replies: 13
    Last Post: 12-05-2011, 05:10 AM
  4. StrComp causing "Invalid use of Null" error
    By sephiroth2906 in forum Programming
    Replies: 5
    Last Post: 09-15-2011, 07:06 PM
  5. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM

Tags for this Thread

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