Solved

Runtime Error 2427 on GotFocus Event

Posted on 2013-05-23
10
492 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
10 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 119

Accepted Solution

by:
Rey Obrero 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now