[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Run-time error '3162'

Posted on 2004-09-10
6
Medium Priority
?
1,023 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 500 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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

Industry Leaders: 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!

Question has a verified solution.

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

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.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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