Results 1 to 6 of 6

Thread: specify default directory with OLEDB

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    specify default directory with OLEDB

    When using ODBC connectivity you can specify a DefaultDir. But with OLEDB you can't use the DefaultDir setting, is there an OLEDB equivalent?

    VB Code:
    1. ' CONNECTION STRING FOR THE DATABASE
    2. '    AccessConnect = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    3. '                    "DBQ=Westfield.MDB;" & _
    4. '                    "DefaultDir=" & App.Path & ";"
    5.  
    6. AccessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    7.                  "Data Source=Westfield.mdb;"
    He who never made a mistake never made a discovery?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: specify default directory with OLEDB

    You should specify it as part of the Data Source parameter, ie:
    VB Code:
    1. AccessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    2.                  "Data Source=" & App.Path & "\Westfield.mdb;"

  3. #3

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: specify default directory with OLEDB

    thanks let me try that
    He who never made a mistake never made a discovery?

  4. #4

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: specify default directory with OLEDB

    Ok, I did that but I must have another issue. I am trying to switch from ODBC to OLEDB, so in my module I am createing a connection. I need to modify my ODBC connection to the new OLEDB. But it appears that I something is wrong. I am getting errors when I call my connection. I guess I need to make some additional changes.

    3709,"The connection cannot be used to perform this operation. It is either closed or invalid in this context.","This error created on:",#2006-02-07 10:07:19#

    This is how I have my connection in my module set up. As you can see I was using ODBC.

    VB Code:
    1. Sub CreateConnection(objConn As Connection)
    2.  
    3. ' CONNECTION STRING FOR THE DATABASE
    4. '    AccessConnect = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
    5. '                    "DBQ=Westfield.MDB;" & _
    6. '                    "DefaultDir=" & App.Path & ";"
    7.  
    8. AccessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    9.                  "Data Source==" & App.Path & "\Westfield.mdb;"
    10.  
    11.                      
    12.                      'MsgBox AccessConnect
    13.  
    14.     ' Create Connection Object and open it
    15.     Set objConn = New ADODB.Connection
    16.  
    17.     objConn.CursorLocation = adUseClient
    18.  
    19.     ' Trap any error/exception
    20.     On Error GoTo AdoError
    21.  
    22.     objConn.ConnectionString = AccessConnect
    23.     objConn.Open
    24.  
    25.     Exit Sub
    26.  
    27.     ' ADO Error/Exception Handler
    28. AdoError:
    29.     ErrNumber = Err.Number
    30.     ErrSource = Err.Source
    31.     ErrDescription = Err.Description
    32.  
    33.     'AdoErrorEx List1, objConn
    34.  
    35. End Sub

    This is how I was calling it from within appilcation, it bombs out on this line and gives me the error above.

    .ActiveConnection = objConn



    VB Code:
    1. 'connect to database, generate ID, add ID to text box
    2.     Call CreateConnection(objConn)
    3.  
    4.     'MsgBox objConn.State
    5.     Set objRs = New ADODB.Recordset
    6.  
    7.     With objRs
    8.         .ActiveConnection = objConn
    9.         .CursorLocation = adUseClient
    10.         .CursorType = adOpenDynamic
    11.         .LockType = adLockOptimistic
    12.         .Source = "select * from Campaign where 2=3"    '2=3 basically creates a empty record set
    13.         .Open
    14.     End With
    15.  
    16.     '  ADDING RECORDS FROM TEXTBOX TO DATABASE
    17.     With objRs
    18. ....
    He who never made a mistake never made a discovery?

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: specify default directory with OLEDB

    The Connection is not open when it is used as an ActiveConnection.

    The CreateConnection procedure should be generating an error because you have two == signs after Data Source.

    Code:
    AccessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                     "Data Source==" & App.Path & "\Westfield.mdb;"

  6. #6

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: specify default directory with OLEDB

    Man.. what dumb oversight

    Thanks its working now.
    He who never made a mistake never made a discovery?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width