Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Runtime Error 2427 on GotFocus Event

Posted on 2013-05-23
10
Medium Priority
?
517 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
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 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 2000 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

705 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