Solved

Run-time error '3162'

Posted on 2004-09-10
6
872 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
  • 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now