Solved

Runtime Error 2427 on GotFocus Event

Posted on 2013-05-23
10
500 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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