Solved

Run-time error '3162'

Posted on 2004-09-10
6
902 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to save new report from old one 9 30
Need help constructing a conditional update query 16 46
Dcount help 2 16
combo box query 6 6
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

777 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