Solved

Runtime Error 2427 on GotFocus Event

Posted on 2013-05-23
10
511 Views
Last Modified: 2013-05-23
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
0
Comment
Question by:hopelessinsalem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39192300
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 ?
0
 

Author Comment

by:hopelessinsalem
ID: 39192393
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.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39192424
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
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 48

Expert Comment

by:Dale Fye
ID: 39192439
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?
0
 

Author Comment

by:hopelessinsalem
ID: 39192477
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
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39192513
First in the design view of the Form, select the combo box then hit F4
select the Event tab and look for the On Focus Event and see if you have [Event Procedure]


then, do a Compact and Repair
then from VBA window do,

Debug >Compile

correct any errors raised, then try the codes again

try this one, too

Private Sub ALChoice_GotFocus()
    If Me.ALChoice.Listindex=-1  Then
        Me.ALChoice.BackColor = 255
        Me.ALChoice.Dropdown
    Else
        Me.ALChoice.BackColor = 16777215
    End If
End Sub

if tht doesn't work, upload a copy of your db
0
 

Author Closing Comment

by:hopelessinsalem
ID: 39192548
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.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39192553
<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
0
 

Author Comment

by:hopelessinsalem
ID: 39192588
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?
0
 

Author Comment

by:hopelessinsalem
ID: 39192616
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.

Bacground Color Change - Combo Box
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question