Solved

Run-time error '3162'

Posted on 2004-09-10
6
933 Views
Last Modified: 2011-10-03
I have an after-update event procedure for a combo box that populates a second combo box with the following:

Private Sub CategoryID_AfterUpdate()
Me!ProductID.Requery
ProcuctID = PruductID.ItemData(0)
End Sub

The problem is that if a category is selected in which there are no products, I get a Run-time error '3162' saying that I tried to assign a null valuable to a variable that isn't a variant data type.

How can I get around this?

Thanks.
RWW
0
Comment
Question by:PstWood
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 36

Expert Comment

by:SidFishes
ID: 12031058
simple way is to declare your variable as variant ;)

Dim ProductID as Variant

otherwise you'll have to trap for null

ProcuctID = iif(isnull(PruductID.ItemData(0)), "", PruductID.ItemData(0))

0
 
LVL 18

Accepted Solution

by:
Data-Man earned 125 total points
ID: 12031062
Try this

Private Sub CategoryID_AfterUpdate()
     Me!ProductID.Requery
     If Me.ProductID.Listcount<>0 Then
          ProcuctID = PruductID.ItemData(0)
     End If
End Sub


Mike
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 12031072
btw this assumes that ProcuctID IS a variable ...(since access is assuming it is)

if you are trying to assign a value to a control (textbox) do this

me!ProcuctID = iif(isnull(PruductID.ItemData(0)), "", PruductID.ItemData(0))
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PstWood
ID: 12031376
Thanks.
RWW
0
 

Author Comment

by:PstWood
ID: 12031386
I did have to put a second Me!ProductID.Requery after the End If in order to clear the box if the user chooses a category, then changes his mind and chooses another.
0
 
LVL 18

Expert Comment

by:Data-Man
ID: 12031394
What about this

Private Sub CategoryID_AfterUpdate()
     Me!ProductID.Requery
     If Me.ProductID.Listcount<>0 Then
          ProcuctID = PruductID.ItemData(0)
     Else
          ProductID = ""
     End If
End Sub

Mike
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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