PC Review


Reply
Thread Tools Rate Thread

Connecting Excel to Access Using Late Binding

 
 
Dr. M
Guest
Posts: n/a
 
      25th Nov 2008
Hello! I'm trying to connect to an Access database using Late Binding but my
little simple code will not open the database. I appreciate your help!!!

Sub Test()

Dim strConnection As String
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=M:\database.mdb;"

Dim cn As Object
Set cn = CreateObject("ADODB.Connection")

cn.Open strConnection

' Find out if the attempt to connect worked.
If cn.State = adStateOpen Then
MsgBox "You are connected!"
Else
MsgBox "Sorry. You are not connected."
End If

' cn.Close

End Sub

--
Dr. M
 
Reply With Quote
 
 
 
 
Office_Novice
Guest
Posts: n/a
 
      25th Nov 2008
Try This, this worked for me after referencing Active X Data Objects Lib 2.7

Public Const ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C\: YourDataSource Here."

Public Sub Zero()
Dim Connection As ADODB.Connection
Set Connection = New ADODB.Connection
Connection.Open (ConnectionString)

If Connection.State = adStateOpen Then MsgBox "You Have Connected
Successfully ", vbInformation
If Connection.State = adStateClosed Then MsgBox "Sorry, Connection
Failed", vbCritical

If Connection.State = adStateOpen Then Connection.Close
End Sub


"Dr. M" wrote:

> Hello! I'm trying to connect to an Access database using Late Binding but my
> little simple code will not open the database. I appreciate your help!!!
>
> Sub Test()
>
> Dim strConnection As String
> strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=M:\database.mdb;"
>
> Dim cn As Object
> Set cn = CreateObject("ADODB.Connection")
>
> cn.Open strConnection
>
> ' Find out if the attempt to connect worked.
> If cn.State = adStateOpen Then
> MsgBox "You are connected!"
> Else
> MsgBox "Sorry. You are not connected."
> End If
>
> ' cn.Close
>
> End Sub
>
> --
> Dr. M

 
Reply With Quote
 
Dr. M
Guest
Posts: n/a
 
      25th Nov 2008
Thanks for the tip. However, I'm trying to avoid having to reference the
Active X Data Objects Lib X.X by clicking it as I'm unsure which machine will
actually be running this code. I was hoping more for a programmtic solution.

Thank you!
--
Dr. M


"Office_Novice" wrote:

> Try This, this worked for me after referencing Active X Data Objects Lib 2.7
>
> Public Const ConnectionString = _
> "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data Source=C\: YourDataSource Here."
>
> Public Sub Zero()
> Dim Connection As ADODB.Connection
> Set Connection = New ADODB.Connection
> Connection.Open (ConnectionString)
>
> If Connection.State = adStateOpen Then MsgBox "You Have Connected
> Successfully ", vbInformation
> If Connection.State = adStateClosed Then MsgBox "Sorry, Connection
> Failed", vbCritical
>
> If Connection.State = adStateOpen Then Connection.Close
> End Sub
>
>
> "Dr. M" wrote:
>
> > Hello! I'm trying to connect to an Access database using Late Binding but my
> > little simple code will not open the database. I appreciate your help!!!
> >
> > Sub Test()
> >
> > Dim strConnection As String
> > strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> > "Data Source=M:\database.mdb;"
> >
> > Dim cn As Object
> > Set cn = CreateObject("ADODB.Connection")
> >
> > cn.Open strConnection
> >
> > ' Find out if the attempt to connect worked.
> > If cn.State = adStateOpen Then
> > MsgBox "You are connected!"
> > Else
> > MsgBox "Sorry. You are not connected."
> > End If
> >
> > ' cn.Close
> >
> > End Sub
> >
> > --
> > Dr. M

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      25th Nov 2008
Sorry About that try this

Public Sub Zero()
Dim Connection As Object
Set Connection = CreateObject("ADODB.Connection")
Connection.Open (ConnectionString)

If Connection = "" Then MsgBox "Fail", vbCritical
If Not Connection = "" Then MsgBox "Passed", vbInformation
End Sub

"Dr. M" wrote:

> Thanks for the tip. However, I'm trying to avoid having to reference the
> Active X Data Objects Lib X.X by clicking it as I'm unsure which machine will
> actually be running this code. I was hoping more for a programmtic solution.
>
> Thank you!
> --
> Dr. M
>
>
> "Office_Novice" wrote:
>
> > Try This, this worked for me after referencing Active X Data Objects Lib 2.7
> >
> > Public Const ConnectionString = _
> > "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> > "Data Source=C\: YourDataSource Here."
> >
> > Public Sub Zero()
> > Dim Connection As ADODB.Connection
> > Set Connection = New ADODB.Connection
> > Connection.Open (ConnectionString)
> >
> > If Connection.State = adStateOpen Then MsgBox "You Have Connected
> > Successfully ", vbInformation
> > If Connection.State = adStateClosed Then MsgBox "Sorry, Connection
> > Failed", vbCritical
> >
> > If Connection.State = adStateOpen Then Connection.Close
> > End Sub
> >
> >
> > "Dr. M" wrote:
> >
> > > Hello! I'm trying to connect to an Access database using Late Binding but my
> > > little simple code will not open the database. I appreciate your help!!!
> > >
> > > Sub Test()
> > >
> > > Dim strConnection As String
> > > strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> > > "Data Source=M:\database.mdb;"
> > >
> > > Dim cn As Object
> > > Set cn = CreateObject("ADODB.Connection")
> > >
> > > cn.Open strConnection
> > >
> > > ' Find out if the attempt to connect worked.
> > > If cn.State = adStateOpen Then
> > > MsgBox "You are connected!"
> > > Else
> > > MsgBox "Sorry. You are not connected."
> > > End If
> > >
> > > ' cn.Close
> > >
> > > End Sub
> > >
> > > --
> > > Dr. M

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      25th Nov 2008
You can't use the library constants if you use late binding, so replace

adStateOpen

with the value 1

--
__________________________________
HTH

Bob

"Dr. M" <(E-Mail Removed)> wrote in message
news:987B658A-868B-4F09-B373-(E-Mail Removed)...
> Thanks for the tip. However, I'm trying to avoid having to reference the
> Active X Data Objects Lib X.X by clicking it as I'm unsure which machine
> will
> actually be running this code. I was hoping more for a programmtic
> solution.
>
> Thank you!
> --
> Dr. M
>
>
> "Office_Novice" wrote:
>
>> Try This, this worked for me after referencing Active X Data Objects Lib
>> 2.7
>>
>> Public Const ConnectionString = _
>> "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>> "Data Source=C\: YourDataSource Here."
>>
>> Public Sub Zero()
>> Dim Connection As ADODB.Connection
>> Set Connection = New ADODB.Connection
>> Connection.Open (ConnectionString)
>>
>> If Connection.State = adStateOpen Then MsgBox "You Have Connected
>> Successfully ", vbInformation
>> If Connection.State = adStateClosed Then MsgBox "Sorry, Connection
>> Failed", vbCritical
>>
>> If Connection.State = adStateOpen Then Connection.Close
>> End Sub
>>
>>
>> "Dr. M" wrote:
>>
>> > Hello! I'm trying to connect to an Access database using Late Binding
>> > but my
>> > little simple code will not open the database. I appreciate your
>> > help!!!
>> >
>> > Sub Test()
>> >
>> > Dim strConnection As String
>> > strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
>> > "Data Source=M:\database.mdb;"
>> >
>> > Dim cn As Object
>> > Set cn = CreateObject("ADODB.Connection")
>> >
>> > cn.Open strConnection
>> >
>> > ' Find out if the attempt to connect worked.
>> > If cn.State = adStateOpen Then
>> > MsgBox "You are connected!"
>> > Else
>> > MsgBox "Sorry. You are not connected."
>> > End If
>> >
>> > ' cn.Close
>> >
>> > End Sub
>> >
>> > --
>> > Dr. M



 
Reply With Quote
 
Dr. M
Guest
Posts: n/a
 
      25th Nov 2008
That seemed to do it! Thanks y'all!!!
--
Dr. M


"Bob Phillips" wrote:

> You can't use the library constants if you use late binding, so replace
>
> adStateOpen
>
> with the value 1
>
> --
> __________________________________
> HTH
>
> Bob
>
> "Dr. M" <(E-Mail Removed)> wrote in message
> news:987B658A-868B-4F09-B373-(E-Mail Removed)...
> > Thanks for the tip. However, I'm trying to avoid having to reference the
> > Active X Data Objects Lib X.X by clicking it as I'm unsure which machine
> > will
> > actually be running this code. I was hoping more for a programmtic
> > solution.
> >
> > Thank you!
> > --
> > Dr. M
> >
> >
> > "Office_Novice" wrote:
> >
> >> Try This, this worked for me after referencing Active X Data Objects Lib
> >> 2.7
> >>
> >> Public Const ConnectionString = _
> >> "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> >> "Data Source=C\: YourDataSource Here."
> >>
> >> Public Sub Zero()
> >> Dim Connection As ADODB.Connection
> >> Set Connection = New ADODB.Connection
> >> Connection.Open (ConnectionString)
> >>
> >> If Connection.State = adStateOpen Then MsgBox "You Have Connected
> >> Successfully ", vbInformation
> >> If Connection.State = adStateClosed Then MsgBox "Sorry, Connection
> >> Failed", vbCritical
> >>
> >> If Connection.State = adStateOpen Then Connection.Close
> >> End Sub
> >>
> >>
> >> "Dr. M" wrote:
> >>
> >> > Hello! I'm trying to connect to an Access database using Late Binding
> >> > but my
> >> > little simple code will not open the database. I appreciate your
> >> > help!!!
> >> >
> >> > Sub Test()
> >> >
> >> > Dim strConnection As String
> >> > strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
> >> > "Data Source=M:\database.mdb;"
> >> >
> >> > Dim cn As Object
> >> > Set cn = CreateObject("ADODB.Connection")
> >> >
> >> > cn.Open strConnection
> >> >
> >> > ' Find out if the attempt to connect worked.
> >> > If cn.State = adStateOpen Then
> >> > MsgBox "You are connected!"
> >> > Else
> >> > MsgBox "Sorry. You are not connected."
> >> > End If
> >> >
> >> > ' cn.Close
> >> >
> >> > End Sub
> >> >
> >> > --
> >> > Dr. M

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Late binding Access from Excel Rick Microsoft Access VBA Modules 5 24th Oct 2008 05:16 PM
Late binding to Excel from Access causing Object error EagleOne@microsoftdiscussiongroups Microsoft Excel Misc 4 14th Jun 2008 12:45 AM
Late Binding access reference in Excel Module =?Utf-8?B?Tm9lbWk=?= Microsoft Excel Programming 0 16th Nov 2007 12:54 AM
Late Binding Excel in Access matthew.buis@gmail.com Microsoft Excel Programming 1 31st Jul 2006 03:38 PM
Late Binding examples of binding excel application =?Utf-8?B?SGVhdGhlck8=?= Microsoft Excel Programming 14 17th Mar 2005 08:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:13 PM.