Link to home
Start Free TrialLog in
Avatar of hopelessinsalem
hopelessinsalem

asked on

Runtime Error 2427 on GotFocus Event

Very simple code below that checks to see if value is null and if so make the background red.  This code is on a subform and has worked since I created this little database in 2008.  Today I made some changes to a couple of other subforms and when going through error checking, when I got to this subform all of a sudden I am getting the Run-Time error 2427 - The expression you entered has no value.  The Debug shows the error occurring on the line with the asterisks.

Can someone clue me in as to why this simple code no  longer works?  I have similar code on other forms in this same database that do NOT generate this code.

Private Sub ALChoice_GotFocus()
    If IsNull(Me.ALChoice.value) Or Me.ALChoice.value = 0 Then  ******
        Me.ALChoice.BackColor = 255
        Me.ALChoice.Dropdown
    Else
        Me.ALChoice.BackColor = 16777215
    End If
End Sub
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

What is "ALChoice" a textbox ? is it bound?
What values  do expect in this control?

if you do this,

Private Sub ALChoice_GotFocus()
    If IsNull(Me.ALChoice) Then  ******
        Me.ALChoice.BackColor = 255
        Me.ALChoice.Dropdown
    Else
        Me.ALChoice.BackColor = 16777215
    End If
End Sub

do you still get the error ?
Avatar of hopelessinsalem
hopelessinsalem

ASKER

ALChoice is just a listbox with three choices to choose from (all text values)

I changed the code as you suggested and although the error goes away, the background no longer changes to red.
so, what you are saying is, if there is no selection made, change the color of the dropdown?

try this

Private Sub ALChoice_GotFocus()
    If Me.ALChoice & ""=""  Then
        Me.ALChoice.BackColor = 255
        Me.ALChoice.Dropdown
    Else
        Me.ALChoice.BackColor = 16777215
    End If
End Sub
What version of access did this work in (2007)?  What version are you working in now (2010)?

I don't think I've ever been able to change the backcolor of the listbox like this, and listboxes don't "drop down".  Are you sure you are not talking about a combo box?
capricorn1

Tried that and it didn't work.  And it is bound as you had asked

Fyed

My apologies.  Yes, it IS a combo box.  I believe I created this in 2007, and I do now have 2010.

I actually have another copy of this database that I saved a while back, but I don't want to 'use' since I have updated my current one a few times since then.  The other copy, with the same original code I posted above, works like it always has.  

I have been researching this issue but can't seem to explain why.  I'm no expert by any means, but I find it odd that it just quit working all of a sudden
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I previously tried compacting and repairing, and I also did the Debug/Compile.  Nothing worked when I did that.

Changing the line of code as your 2nd suggestion made it work again!!

Thank you.
<Tried that and it didn't work.>
This is vague, can you clearly state what did, ...or did not happen when you tried capricorn1's suggestion?


Can you tell us what the combobox column properties are:
Bound column, Column count, row source, ...etc
Hoag2000

I tried changing
 If IsNull(Me.ALChoice.value) Or Me.ALChoice.value = 0 Then  

Open in new window

to
  If Me.ALChoice & ""=""  Then 

Open in new window

.  Changing the original code to his suggestion of
If Me.ALChoice.Listindex=-1  Then

Open in new window

got me back to business.

Column count =1, Bound Column =1, List Rows =3, Control Source = ALChoice (from tblAL), Row Source Type is Value List, Row Source lists the three choices I can choose.

Does that help?
This is what I was trying to fix.  What was originally working and is now working again.  There is an option box on the right that hides/un-hides the subform I want to work on.  This sub in particular is the Antenna/Line Info.

User generated image