Link to home
Start Free TrialLog in
Avatar of PstWood
PstWood

asked on

Run-time error '3162'

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
Avatar of SidFishes
SidFishes
Flag of Canada image

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))

ASKER CERTIFIED SOLUTION
Avatar of Data-Man
Data-Man
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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))
Avatar of PstWood
PstWood

ASKER

Thanks.
RWW
Avatar of PstWood

ASKER

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.
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