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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error

Status
Not open for further replies.

BigStuM

Programmer
Mar 18, 2010
3
GB
Hi Guys, here is my first stab at programming using VBA, I need to get this working PDQ, can you see why I am getting this error:
"Compile Error: Function call on left hand side of assignement must return Variant or Object"


Here is the function giving me the problem;

Function Checkload(LoadID As Long) As Boolean

Dim cn As New ADODB.Connection
Dim StrSQL As String

On Error GoTo Errorhandler

cn.Open CurrentProject.Connection

Set rs = New ADODB.Recordset
rs.ActiveConnection = cn
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic

StrSQL = "SELECT * FROM tblConsignment WHERE LoadID = " & LoadID & ""


rs.Open StrSQL, cn

If rs.RecordCount > 0 Then

Checkload(LoadID) = True

Else

Checkload(LoadID) = False

End If

'close connections
rs.Close
cn.Close
Set cn = Nothing
Set rs = Nothing

End Function
 
If rs.RecordCount > 0 Then
Checkload = True
Else
Checkload = False
End If

You will find an example of a function in the help (well it is in access 2000 the version i am using)
 
I commend your efforts in learning programming and ADODB. One thing you will learn is there are always dozens of different solutions for coding functionality. For instance, you function can be written:
Code:
Function Checkload(LoadID As Long) As Boolean
   CheckLoad = DCount("*","tblConsignment","LoadID = " & LoadID) > 0
End Funciton

Duane
Hook'D on Access
MS Access MVP
 
Thanks Guys for the feedback, Ive made the change suggested by huggyboy - Im now recieving a different error, can anyone help;

Error Number 3001. Arguments are of the wrong type, are out of acceptable range or are in conflict with one another.

 
Hi Dhookom, I made a few changes through the day and now have the function working fine thanks for taking teh time to help me.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top