LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Using ADO and Late Binding

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Late binding Brent Excel Programming 2 April 13th 07 03:00 PM
Late Binding Mark Excel Programming 4 October 17th 05 04:02 PM
Late Binding examples of binding excel application HeatherO Excel Programming 13 March 17th 05 08:19 AM
Late Binding help, Please Bud Dean Excel Programming 5 September 24th 04 04:31 AM
EARLY binding or LATE binding ? jason Excel Programming 6 February 26th 04 04:57 PM


All times are GMT +1. The time now is 11:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"