Log in

View Full Version : How to pass recordsets as arguments both byval and byref?



prabhafriend
07-12-2010, 06:53 AM
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)

Imdabaum
07-12-2010, 09:34 AM
Function List_Respo(ByVal argset As Recordset)
Function List_Respo(ByRef argset As Recordset)

prabhafriend
07-13-2010, 01:08 AM
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.

prabhafriend
07-15-2010, 08:54 AM
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.

Imdabaum
07-15-2010, 09:36 AM
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 (http://msdn.microsoft.com/en-us/library/ddck1z30(VS.71).aspx) and follow the links.

prabhafriend
07-19-2010, 01:16 AM
Call List_Respo(userset) allows transporting recordsets between functions but not List_Respo(userset). It's silly man. Anyway, Thanks Imdabaum.

prabhafriend
07-19-2010, 01:26 AM
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.

Imdabaum
07-20-2010, 09:41 PM
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.

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

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.