|
-
Apr 10th, 2005, 11:24 PM
#1
Thread Starter
Fanatic Member
[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
-
Apr 10th, 2005, 11:45 PM
#2
Junior Member
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:
Private Sub cmdInsertIp_Click()
Dim conDB As New ADODB.Connection
conDB.Open "Provider='Microsoft.JET.OLEDB.4.0';" & _
"Data Source='C:\vb6files\FtpIpFiles\ip.mdb'"
conDB.Execute "INSERT INTO CurrentIp VALUES ('" & Text2.Text & "')"
conDB.Close
Set conDB = Nothing
End Sub
Hope this helps.
Regards,
-
Apr 11th, 2005, 01:43 AM
#3
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|