visual basic connect to access database

i am trying to connect an Access database with Visual Basic 6.0 using DAO.

my codes goes like this:

Const CONNECT$ = "ODBC;uid=;pwd=;driver={Microsoft Access Driver                                 (*.mdb)};database=;dsn=myDB;"

Public wrkMaster As Workspace
Public cnnMaster As Connection

Set wrkMaster = DBEngine.CreateWorkspace("", "", "", dbUseODBC)
Set cnnMaster = wrkMaster.OpenConnection("myDB",                                                    dbDriverNoPrompt, False, CONNECT$)


whenever i try to run these codes, VB gives me the error 3059 - "Operation cancelled by user"

is there anything wrong with the codes or ODBC setting??
oddzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BrianWrenCommented:
I suspect, though I can't find confirmation of this, that the driver needs to be a quoted string.  Additionally, there is really a LOT of apparently excess space in your strings.  Again, I'm not certain on this, but I think that what you should have is:

Const CONNECT$ = "ODBC;uid=;pwd=;driver=""Microsoft Access Driver (*.mdb)"";database=;dsn=myDB;"
' A pair of double quotes in a row is coverted into a single double-quote in the
string.  "Hello ""Joe"" my friend!" becomes: Hello "Joe" my friend!

Public wrkMaster As Workspace
Public cnnMaster As Connection

Set wrkMaster = DBEngine.CreateWorkspace("", "", "", dbUseODBC)
Set cnnMaster = wrkMaster.OpenConnection("myDB", dbDriverNoPrompt, False, CONNECT$)

Or:
 
Const CONNECT$ = "ODBC;uid=;pwd=;driver=""{Microsoft Access Driver (*.mdb)}"";database=;dsn=myDB;"

Public wrkMaster As Workspace
Public cnnMaster As Connection

Set wrkMaster = DBEngine.CreateWorkspace("", "", "", dbUseODBC)
Set cnnMaster = wrkMaster.OpenConnection("myDB", dbDriverNoPrompt, False, CONNECT$)

Brian
0
CEBAKACommented:
Connect$="dsn=myDB;" should be enough. But you have to make a odbc entry manual. Could you check this?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.