Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi. I use Office 2k and have made a function that should return
a sum from a Access database using ADO. My function works fine as long as I set a reference to ADO 2.8. However, I want to use late binding because the function should be used of different users with different versions of ADO. Setting a reference to ADO 2.8 when only ADO 2.6 is installed on the users machine, will cause an error. Therefore rather than setting the reference from Tools/References I use the CreateObject function to set a reference. When running the code below, it works fine when I set the reference. But when I uncheck the reference I get error code 3001, The arguments are of wrong type, out of valid range or in conflict with each other? How is this possible when I use late binding? When setting a reference there is no problem even without changing any code. I thought that CreateObject would do the same as setting a reference, right? Here is the code I use: Function SjekkTimerPeriode(lngId As Long, lngDays As Long, _ Optional myDate As Date = 0, Optional lngArbØkt As Long = 0) As Double Dim strSQL As String Dim strDato As String Dim objCon As Object Dim objRst As Object Set objCon = CreateObject("ADODB.Connection") Set objRst = CreateObject("ADODB.Recordset") If myDate = 0 Then myDate = Date If IsNull(lngId) Then SjekkTimerPeriode = 0 Exit Function End If strDato = "#" & Month(myDate) & "/" & Day(myDate) & "/" & Year(myDate) & "#" strSQL = "SELECT Sum(([TilTid]-[FraTid])*24) AS AntallTimer" strSQL = strSQL & " FROM AvspaseringOvertid" strSQL = strSQL & " WHERE (((AvspaseringOvertid.Ansattid)=" & lngId & " )" If lngArbØkt < 0 Then strSQL = strSQL & " AND (AvspaseringOvertid.ArbØktId < " & lngArbØkt & ")" End If strSQL = strSQL & " AND ((AvspaseringOvertid.ArbeidsDato)" strSQL = strSQL & " Between " & strDato & " - " & lngDays & " And " & strDato & ")" strSQL = strSQL & " AND (AvspaseringOvertid.RealiserTil < 4));" ' open the connection With objCon .Provider = "Microsoft.Jet.OLEDB.4.0" .Open gstrDBfil ' S: End With ' Define the Recordset objRst.CursorLocation = adUseServer 'HERE I GET AN ERROR ' open the table AND THEN NEXT LINES... objRst.Open Source:=strSQL, _ ActiveConnection:=objCon, _ CursorType:=adOpenDynamic, _ LockType:=adLockOptimistic, _ Options:=adCmdText If IsNull(objRst("AntallTimer")) Then SjekkTimerPeriode = 0 Else SjekkTimerPeriode = objRst("AntallTimer") End If objRst.Close Set objRst = Nothing End Function ----------------------------------------------------------------- Any help with this would be very much appreciated. Thanx in advance! Regards Jan |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Late binding | Excel Programming | |||
Late Binding | Excel Programming | |||
Late Binding examples of binding excel application | Excel Programming | |||
Late Binding help, Please | Excel Programming | |||
EARLY binding or LATE binding ? | Excel Programming |