Results 1 to 3 of 3

Thread: [resolved]access ado database

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Cool [resolved]access ado database

    Ok this is my fisrt attempt at working with data bases
    I have made a form that creates an access database, then creates a row.
    Code:
    Private Sub Command1_Click()
    
       Text2.Text = GetPublicIP()
           Dim conCatalog As ADOX.Catalog
        On Error Resume Next
        Set conCatalog = New ADOX.Catalog
        conCatalog.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                          "Data Source='C:\vb6files\FtpIpFiles\ip.mdb'"
        
        MsgBox "A new Microsoft JET database named IP.mdb has been created"
        
        Set conCatalog = Nothing
        
        Dim conIp As ADODB.Connection
        Dim strSQL As String
        
        Set conIp = New ADODB.Connection
        conIp.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                          "Data Source='C:\vb6files\FtpIpFiles\ip.mdb'"
        
        strSQL = "CREATE TABLE CurrentIp (" & _
                 "Ip VarChar(32));"
        
        conIp.Execute strSQL
        
        MsgBox "A table named IpAddy has been added to the IP.mdb database"
    Now I need to insert the value of text2,txt into the data base, this is my code so far,
    Code:
    Private Sub cmdInsertIp_Click()
        Dim conIp As New ADODB.Recordset
        Dim conCatalog As New ADODB.Connection
    
    conCatalog.Open "Provider='Microsoft.JET.OLEDB.4.0';" & _
                          "Data Source='C:\vb6files\FtpIpFiles\ip.mdb'"
       
    
    If conIp.Supports(adAddNew) Then
    
            With conIp
                .AddNew
                .Fields("ip") = Me.Text2.Text
                .Update
            End With
            
            MsgBox "text2.txt has been added"
        End If
        
        
        Me.Text2.SetFocus
    
      
        
    
    
        
        Set conIp = Nothing
        conCatalog.Close
        Set conCatalog = Nothing
    End Sub
    it does not work but does not return error either?
    please help, thanks
    Last edited by planethax; Apr 11th, 2005 at 01:16 AM. Reason: resolved

  2. #2
    Junior Member
    Join Date
    Nov 2003
    Posts
    22

    Re: access ado database

    In the second piece of code the "conIp" recordset is not connected to the database, thus updating it will not update the database. You can eliminate the need for the recordset completely by using a SQL INSERT statement. Example:

    VB Code:
    1. Private Sub cmdInsertIp_Click()
    2. Dim conDB As New ADODB.Connection
    3.  
    4. conDB.Open "Provider='Microsoft.JET.OLEDB.4.0';" & _
    5.            "Data Source='C:\vb6files\FtpIpFiles\ip.mdb'"
    6.  
    7. conDB.Execute "INSERT INTO CurrentIp VALUES ('" & Text2.Text & "')"
    8.  
    9. conDB.Close
    10. Set conDB = Nothing
    11. End Sub

    Hope this helps.

    Regards,

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    651

    Re: [resolved]access ado database

    Thanx jlbeam the was perfect!!! )

    Next problem I am having is that I need to update a database (at www.planethax.com)
    with the with the currentip table field ip.
    the database for my app is
    ip.mdb
    table is CurrentIp
    field is Ip

    my database online is
    mydb2
    table is IpTbl
    field is IpFld

    any help with the code I need to update the online db with the local one will be greatly appreciated!
    Thanks.

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