Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    What's with the type mismatch?


    Not used to using hex values this way, but nonetheless don't understand what the issue might be?
    Code:
    If Not IsNull(Form.ActiveControl) Then
        Form.ActiveControl.BackColor = CLng("&FFFFFF")
    Else
        Form.ActiveControl.BackColor = CLng("&F8BABB")
    End If

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    This should work

    .BackColor = &HF8BABB

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    That's what I started with, but got compiler error "Expected Expression"
    Code:
    If Not IsNull(Form.ActiveControl) Then
        Form.ActiveControl.BackColor = &FFFFFF
    Else
        Form.ActiveControl.BackColor = &F8BABB
    End If

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Why not just use Conditional Formatting?

    This works, but I could not get the white to render using the hex
    Code:
    Private Sub txtFactor_GotFocus()
    Me.txtFactor.BackColor = Val("&F8BABB")
    End Sub
    
    
    Private Sub txtFactor_LostFocus()
    Me.txtFactor.BackColor = vbWhite
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by GraeagleBill View Post
    That's what I started with, but got compiler error "Expected Expression"
    Code:
    If Not IsNull(Form.ActiveControl) Then
        Form.ActiveControl.BackColor = &FFFFFF
    Else
        Form.ActiveControl.BackColor = &F8BABB
    End If

    Look carefully at my suggestion. You left out the H

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    You left out the H
    Completely missed that. Like I said at the OP, not used to doing much with hex. (and that's coming from an old bit twiddle'r)

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    If you want white, could use vbWhite.

    &HF8BABB returns a light shade of bluish-grey. Is that what you expect?

    Review
    https://stackoverflow.com/questions/...-ms-access-vba
    Access Colour (color) Codes - jhTuppeny Consulting
    RGB function (Visual Basic for Applications) | Microsoft Learn

    My attempt to interpret this info:
    ID ColorName ColorCodeDec ColorCodeRGB ColorCodeHex HexGBR
    1 Black 0 000,000,000 000000 &H0
    2 Red 255 255,000,000 FF0000 &HFF
    3 Green 65280 000,255,000 00FF00 &HFF0000
    4 Yellow 65535 255,255,000 FFFF00 &HFF00FF
    5 Blue 16711680 000,000,255 0000FF &HFF00
    6 Magenta 16711935 255,000,255 FF00FF &HFFFF
    7 Cyan 16776960 000,255,255 00FFFF &HFFFF00
    8 White 16777215 255,255,255 FFFFFF &HFFFFFF
    The &H value will not retain leading zeros so &H0000FF becomes &HFF - Red.
    I cannot get &H code to work for yellow, green, blue, magenta.

    Suggest you stick with RGB() function.
    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.

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Now, if I could just find the right expression for the conditional formatting!
    Click image for larger version. 

Name:	000.jpg 
Views:	18 
Size:	17.6 KB 
ID:	51086

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Code:
    If Not IsNull(Form.ActiveControl) Then
        Form.ActiveControl.BackColor = vbWhite
    Else
        Form.ActiveControl.BackColor = RGB(248, 186, 187)
    End If
    Good thinking, this code works nicely. Still think the simple conditional formatting solution Welshgasman suggested is best if I can find the correct expression.

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I'd bet a dollar that you've been told that there is nothing that equals null, or would have read that by now. If I'm wrong, you'll have to come and get your money.
    If sticking with the formatting tool I suspect you'd have to use "Expression Is" not "Field value is".
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Use Expression Is and this type of thing:

    IsNull([txtReqDate])
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by Micron View Post
    I'd bet a dollar that you've been told that there is nothing that equals null, or would have read that by now. If I'm wrong, you'll have to come and get your money.
    LOL! Concur, and I'm easier to collect from since we live in the same city.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    there is nothing that equals null
    Yes, my post was more-or-less one of the many silly things I tried. Your money is safe
    Have a happy Thanksgiving.

  14. #14
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Both post #9 and Conditional Formatting solved the OP. The only downside the is with CF'g is that, in design mode, the TB's show the back color shading of those fields that are subject to special processing. I.e., in need of shading when null. (I realize I can add some additional CF'g when Not IsNull)

  15. #15
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Have a happy Thanksgiving.
    That was 6 weeks ago, but same to you anyway.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Intermittant #Type! type mismatch error.
    By Ranger351w in forum Programming
    Replies: 4
    Last Post: 09-27-2020, 07:53 PM
  2. Type mismatch but ONLY when run via VBA?
    By mcucino in forum Programming
    Replies: 5
    Last Post: 03-19-2019, 06:46 PM
  3. Type Mismatch
    By Alex Motilal in forum Programming
    Replies: 5
    Last Post: 02-04-2017, 05:57 PM
  4. Type 13 (Type Mismatch) error
    By sdel_nevo in forum Programming
    Replies: 5
    Last Post: 01-22-2016, 10:01 AM
  5. Type Mismatch
    By Alex Motilal in forum Programming
    Replies: 10
    Last Post: 02-13-2011, 05:42 AM

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