Results 1 to 14 of 14
  1. #1
    nslemmons is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    7

    Run Time Error '438' - BackColor

    Hey all.



    I'm having a wierd issue with this error. I am referencing a variable for all controls on a form and when this code runs I'm getting the 438 error (Object doesn't support this property or method).

    I'm trying to highlight controls that are null and then I want them to turn white after they've been highlighted. Any help is appreciated.

    Here's the code I have.

    Code:
    Private Sub cmdTest_Click()
    Dim billTo
    Dim ctl As Control
    billTo = Me.cmbBillTo.Value
    For Each ctl In Me.Controls
        If IsNull(ctl) Then
                ctl.BackColor = &HEC2FF
        End If
    Next ctl
            MsgBox "Enter all fields.", vbExclamation
            
                For Each ctl In Me.Controls
                    ctl.BackColor = vbWhite
                Next ctl
    Exit Sub
        If DCount("*", "qryRecordCheck") = 0 Then
            DoCmd.OpenQuery "qryTempPricing"
                MsgBox billTo & " has been successfully added!"
            Else
                If MsgBox("This record already exists. Would you like to overwrite it?", 20, "Record Exists!") = vbYes Then
                    DoCmd.OpenQuery "qryTempPricing"
                    Else
                        MsgBox "No change made to Pricing Table", 64, "Info"
                End If
        End If
    End Sub
    Thanks,
    Nathan

  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,521
    Not weird at all when you realize that not every type of control has a backcolor property. You might want to either use the Tag property to limit the controls tested to those you want or use ctl.ControlType to limit the controls tested to the type of control you want, like text boxes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    nslemmons is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    7
    Thanks Paul.

    What I noticed is further up in the code I use that same method with success. ctl.BackColor = &HEC2FF

    Why does it not work in the second case?

    Also I have both combo boxes and text boxes. How could I accomplish looping through them to set the BackColor?

    Thanks again.
    Nathan

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Presumably the controls that would error are excluded by the Null test. You can add this inside your loop:

    Code:
        Select Case ctl.ControlType
          Case acTextBox, acComboBox
            ctl.BackColor = vbWhite
        End Select
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    nslemmons is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    7
    Paul,

    Thank you sir. That worked great. I'll have to study this more so I have a better understanding of what is happening as it executed this code.

    I really appreciate it!

    Thank you,
    Nathan

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem Nathan, and welcome to the site by the way! Post back if you don't understand anything.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    nslemmons is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    7
    Paul,

    I do have another issue I discovered with this. My form also has buttons which I assume are controls. So when I run the code I end up with the message box saying "Enter all fields.". I presume this is because it's looping through the buttons as well as the text and combo boxes.

    I'm not sure how to work around that.

    Code:
    Private Sub cmdTest_Click()
    Dim billTo
    Dim ctl As Control
    billTo = Me.cmbBillTo.Value
    For Each ctl In Me.Controls
        If IsNull(ctl) Then
                ctl.BackColor = &HEC2FF
        End If
    Next ctl
            MsgBox "Enter all fields.", vbExclamation
            
                For Each ctl In Me.Controls
                    Select Case ctl.ControlType
                    Case acTextBox, acComboBox
                    ctl.BackColor = vbWhite
                    End Select
                Next ctl
    Exit Sub
        If DCount("*", "qryRecordCheck") = 0 Then
            DoCmd.OpenQuery "qryTempPricing"
                MsgBox billTo & " has been successfully added!"
            Else
                If MsgBox("This record already exists. Would you like to overwrite it?", 20, "Record Exists!") = vbYes Then
                    DoCmd.OpenQuery "qryTempPricing"
                    Else
                        MsgBox "No change made to Pricing Table", 64, "Info"
                End If
        End If
    End Sub
    Thank you,
    Nathan

  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,521
    Well, based on its placement your message box is going to run no matter what. Can you clarify what you're trying to accomplish? As written, it will change the backcolor of any null control, but then it turns right around and changes all of them to white. What's the purpose of the first bit?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    nslemmons is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    7
    Well Paul you are correct. That message will run with it being where it is. I didn't notice that.

    so what I'm trying to accomplish is highlighting fields that are not filled out. The first bit is just saying "Hey these are empty!" Then they change back because it's annoying to look at those fields all colored in. And the text is hard to read.

    Does that help?

    Thank you,
    Nathan

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, if the first part is working correctly, add a variable in there that you set if/when it finds a Null control. Then test that variable and only fire off your message box if a null was found.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    nslemmons is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    7
    Paul,

    Sorry it's been a few days.

    I thought that's what I was doign with the If statement inside the For Each statement. I take it I'm not interpreting that correctly?

  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
    I meant:

    Code:
    Dim booNullFound As Boolean
    
    For Each ctl In Me.Controls   
      If IsNull(ctl) Then     
        ctl.BackColor = &HEC2FF
        booNullFound = True   
      End If 
    Next ctl
    
    If (booNullFound) Then
       MsgBox "Enter all fields.", vbExclamation
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    nslemmons is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    7
    Paul,

    Thank you sir. I do believe that will work.

    Thanks again,
    Nathan

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help Nathan.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 03-27-2012, 01:40 PM
  2. If/Else If help to Change BackColor
    By SpdRacerX in forum Access
    Replies: 2
    Last Post: 03-20-2012, 10:09 AM
  3. Flash Textbox Backcolor White and Red
    By Power in forum Programming
    Replies: 3
    Last Post: 10-13-2011, 03:53 PM
  4. simple backcolor code ?
    By markjkubicki in forum Forms
    Replies: 7
    Last Post: 09-16-2011, 12:25 PM
  5. Replies: 1
    Last Post: 10-22-2009, 03:32 AM

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