VB and MS Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pankaj Khera
    New Member
    • Sep 2011
    • 1

    #1

    VB and MS Access

    I have written the following code.however, it is showing me an error on conn.open Please help me out as to what changes to make in it

    Code:
    Dim conn As ADODB.Connection
    Dim rs As ADODB.Recordset
    
    Private Sub Form_Load()
    Set conn = New ADODB.Connection
    conn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data souce='My Documents\cityfk2003.mdb;'"
    conn.Open
    Set rs = New ADODB.Recordset
    rs.Open "select City from table1", conn
    Do While Not rs.EOF
    citycombo.AddItem rs("City")
    rs.MoveNext
    Loop
    End Sub
    Last edited by NeoPa; Sep 30 '11, 11:06 AM. Reason: Added mandatory [ CODE ] tags for you
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You need to use the full path.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      "My Documents" is a pseudo-address. It cannot be used in all places where an address is required. It's also not a very well considered location for storing a database.

      You should consider moving the database to somewhere more appropriate or, alternatively, find where the actual address of "My Documents" and use that instead.

      Comment

      • dsatino
        Contributor
        • May 2010
        • 393

        #4
        also 'data source' is misspelled in the string

        Comment

        Working...