There are a couple of typos, but the only real problem seems to be that the
date to be inserted isn't included in single quotes. When these are
corrected, the code worked fine for me (using the SQL Server provider):
Dim adoCommand As ADODB.Command
Dim ConnectString As String
Dim Sql As String
Set adoCommand = New ADODB.Command
ConnectString = "Provider=SQLOLEDB;Data Source=JULIANS;Initial
Catalog=Test;User ID=sa;Password="
Sql = "INSERT INTO TPSLog(PhoneNum, DateOfSearch, NumberFound) VALUES('" &
PhoneNum & "', '" & Now() & "', '" & NumberFound & "')"
adoCommand.ActiveConnection = ConnectString
adoCommand.CommandText = Sql
adoCommand.CommandType = adCmdText
adoCommand.Execute
There's also a typo in the provider name ('OLDEDB' instead of 'OLEDB'). Hope
this solves your problem.
Julian Skinner
Technical Editor, Wrox Press
http://www.wrox.com/
julians@w...
-----Original Message-----
From: texter@o... [mailto:texter@o...]
Sent: Friday, April 21, 2000 7:48 PM
To: professional vb
Subject: [pro_vb] Insert Query
I have a section of code, that does an update. However, when the code
executes, it doesn't cause an error, but the data is never inserted into
the database. The code is as follows:
Dim adoCommand As ADODB.Command
Dim ConnectString As String
Dim Sql As String
Set adoCommand = New ADODB.Command
ConnectString = "Provider=Microsoft.Jet.OLDEDB.3.51;Data Source=" &
App.Path & "\NumberCheck.mdb"
Sql = "INSERT INTO TPSLog(PhoneNum, DateOfSearch, NumberFound) VALUES('" &
PhoneNum & ", " & Now() & ", " & NumberFound & ")
adoCommand.ActiveConnection = ConnectString
adoCommmand.CommandText = Sql
adoCommand.CommandType = adCmdText
adoCommand.Execute
In this code, PhoneNum and NumberFound are variables passed as parameters.
Any ideas as to why this doesn't work?
Many Thanks,
James