Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with call in vb routine 1

Status
Not open for further replies.

DwayneS

Instructor
Mar 29, 2002
70
Novice programmer; having problem with simple code routine.

I have an input form written and it works. I have subs written to do perform appropriate print routines.

I can't get call to work. Error says "Expected sub, function, or property" I must have made a rookie coding error. Can anyone help?

Here's the code that won't work:

Sub CommandButton1_Click()
Dim x As Integer
Dim RepToPrint As String
For x = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(x) = True Then
RepToPrint = ListBox1.List(x)
' Using this line just to confirm that the loop
' is working. It works
MsgBox ListBox1.List(x)

' I can't get either of these following lines to work
' I have written subs named the same as the values of the UserForm
' and the subs work.

' Call RepToPrint
' Call ListBox1.List(x).Value
End If
Next x
' Close the UserForm.
Unload Me
End Sub


Dwayne Streeter, CPA, CITP
 
RepToPrint (ListBox1.List(x))is presumablty the name of the report you want to print.


You will need a seperate print routine for example

Sub PrintReport (ByVal RepToPrint As String)
'Do the printing here
End Sub

and your calling code would use either

PrintReport RepToPrint

or

Call PrintReport(RepToPrint)


Hope this helps.

[vampire][bat]
 
I'm not sure what you mean exactly about writing subs named the same as the values of the UserForm. A Form is essentially class module hence you can do strange and wonderful things. Either way in this case you can't call a variable that has been declared as a string. Off the top of my head I'd say you have to approach it with conditional statements or use something like this:

Select Case ReptoPrint
case "Routine1"
Call Routine1 'Here is a case where routine name is same as string value. It can make for confusion.
case "Routine2"
Call PrintTheReport
case else
'more code
end select

or

sg=ListBox.List(x).value
Select Case sg
case "Routine1"
Call Routine1
case "Routine2"
Call PrintTheReport
case else
'more code
end select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top