Consulting

Results 1 to 8 of 8

Thread: How to pass recordsets as arguments both byval and byref?

  1. #1

    How to pass recordsets as arguments both byval and byref?

    Private Sub Form_Load()
    'UserName authorization
    Dim userset As Recordset
    Set userset = CurrentDb.OpenRecordset("SELECT * FROM User WHERE Loginid='" & fOSUserName & "';")
    If Not (userset.BOF And userset.EOF) Then List_Respo (userset) Else MsgBox "You are Not Authorised to Access this Application"
    End Sub

    Function List_Respo(argset As Recordset)

  2. #2
    VBAX Expert Imdabaum's Avatar
    Joined
    Jun 2006
    Posts
    652
    Location
    [VBA]Function List_Respo(ByVal argset As Recordset)
    Function List_Respo(ByRef argset As Recordset)[/VBA]
    Someday I'll understand everything...
    Even then...I'll still pretend I'm a beginner.

  3. #3
    Hello... It's a combined question of two. First is How to pass recordset object as a argument? For instance List_Respo(Userset) not working.

  4. #4
    Can someone please explain how to transport recordset in between function procedures as arguments. I know its' definitely possible but don't know how. Kindly help.

  5. #5
    VBAX Expert Imdabaum's Avatar
    Joined
    Jun 2006
    Posts
    652
    Location
    I've included a quick sample of how it works. You can modify the PassingRecordset function as you wish to get more comfortable with the process.

    Just remember, when creating a recordset from queries or after passing them into a function, you need to go to the last record and back to the first to update the recordcount. rst.Movelast rst.MoveFirst.

    Hope that gives you a better idea.

    For more information on ByRef and ByVal
    Click here and follow the links.
    Someday I'll understand everything...
    Even then...I'll still pretend I'm a beginner.

  6. #6
    Call List_Respo(userset) allows transporting recordsets between functions but not List_Respo(userset). It's silly man. Anyway, Thanks Imdabaum.

  7. #7
    Friends I want to know the difference between calling a function with a Call keyword and without a Call keyword. Can Someone please explain why my function works when I included the Call keyword and why not when I didn't. I want to understand the role of the Call keyword in this solution. Please explain.

  8. #8
    VBAX Expert Imdabaum's Avatar
    Joined
    Jun 2006
    Posts
    652
    Location
    Quote Originally Posted by prabhafriend
    Friends I want to know the difference between calling a function with a Call keyword and without a Call keyword. Can Someone please explain why my function works when I included the Call keyword and why not when I didn't. I want to understand the role of the Call keyword in this solution. Please explain.
    Sorry. Simple fact I looked over.

    [vba]Function fnName([with or without parameters])
    Code....
    End function

    Sub TestfnName()
    fnName [optional parameter]
    ' or if you want to use parenthesis
    Call fnName([optional parameters])
    End Sub
    [/vba]
    Yes it's as simple as that. If you want to call a function and love to see your parenthesis at work, use the Call keyword. If you aren't a fan of parenthesis and you aren't returning a value from your function, you don't need the parenthesis.
    Someday I'll understand everything...
    Even then...I'll still pretend I'm a beginner.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •