Open a report using a combobox on a form

R

randria

Hello, I m posting this again because I received an error msg after sending
my first msg.
I have 2 reports "vrpt1" and "vrpt2" , and a combo "vchTxt" that has a
dropdown list of voucher numbers. After the user select a value from the
list, I want access to check the value a column(4) and if the value is 12 or
9 or 5 then vrpt1 should open else vrpt2. Running my code at the moment , it
opens only vrpt2 . Can someone help please.

Private Sub VchTxt_AfterUpdate()
On Error GoTo Err_VchTxt_AfterUpdate

Dim stDocName As String
Dim stLinkCriteria As String
Dim i As Long


stLinkCriteria = "[VoucherN0]=" & Me![VchTxt]
i = Nz(Me.VchTxt.Column(4), 0) 'If I remove nz() then it gives error
"Invalid use of null"

If i = 12 Or i = 9 Or i = 5 Then
stDocName = "vrpt1"
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
Else
stDocName = "vrpt3"
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
End If

Exit_VchTxt_AfterUpdate:
Exit Sub

Err_VchTxt_AfterUpdate:
MsgBox Err.Description
Resume Exit_VchTxt_AfterUpdate
End Sub

What is wrong with my code ?
thank you in advance.
 
C

Carl Rapson

Since removing the Nz function gives an 'invalid use of Null' error, there
seems to be a problem with Column(4) of your combo box. First thought: the
columns in a combo box are zero-based, so a combo box with 4 columns would
be 0,1,2,3. Do you want the 4th column, and so should use Column(3)? Or do
you really want the 5th column, referred to as Column(4)?

Second thought, is Column(4) a Long value? If not, you may need to convert
it:

i = CLng(Nz(Me.VchTxt.Column(4), 0))

HTH,

Carl Rapson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top