Calling a function & passing variables

Tee2

Registered User.
Local time
Yesterday, 21:13
Joined
May 28, 2015
Messages
23
I'm very new to all of this so apologies for my inexperience. I have been slowly working on a new database in Access for work and have run into another road block.

I have never tried passing variables while calling a function so I don't know what the heck I'm doing. I'll give a simplified example of what I'm trying to do I was hoping someone would give some insight as to what I'm doing wrong. The second variable vRank is reporting properly but the first one vID gets "stuck" on whatever the first item in the listbox is. I was convinced I was doing something outside of the code that was causing the problem but I have run out of ideas as to what that would be. I would really appreciate if someone could look over the code and explain what I've done wrong or if the code should be working and I did screw up something in the setup.

Code:
Dim vrt As Variant
Dim upSQL As String

For vrt = 0 To Me.List1.ListCount - 1
    If Me.List1.Selected(vrt) = True Then
        Call ChangeUp(Me.List1.Column(0, vrt), Me.List1.Column(1, vrt))
    End If
Next

End Sub


Sub ChangeUp(vID As Long, vRank As Long)

      MsgBox vID & " " & vRank

End Sub


Thanks!
 
FYI as you do with msgbox

Call ChangeUp(Me.List1.Column(0, vrt), Me.List1.Column(1, vrt))

can be stated as
ChangeUp Me.List1.Column(0, vrt), Me.List1.Column(1, vrt)

but the first one vID gets "stuck" on whatever the first item in the listbox is.
what does 'stuck' mean? you get an error? if so, what is the error description? the system hangs and you have to close access?

why have you declared vrt as variant? why not integer or long?
 
Thanks for the responses. That's a bit awkward, I found a pretty obvious error in my code so it was actually working exactly as written, it just wasn't what I had intended it to do! Which seems to often be the case. I thought I'd looked over it a dozen times so carefully, I guess I just needed the weekend away from it to think more clearly.

As for the variant, I had built this based on code written by someone smarter than me but you're very right there is no reason in this case to be using that.

Thanks again!
 

Users who are viewing this thread

Back
Top Bottom