bs0d
Well-known Member
- Joined
- Dec 29, 2006
- Messages
- 622
I've managed to query my MS Access database through Excel using the ADO method.
I'd like to learn how the syntax differs for an INSERT query; specifically when inserting values from a form.
Here is the code I use for a SELECT query:
And here is the insert query i'd like to execute:
I'd like to learn how the syntax differs for an INSERT query; specifically when inserting values from a form.
Here is the code I use for a SELECT query:
Code:
Set myConnection = New ADODB.Connection
Set myResults = New ADODB.Recordset
FilePath = "L:\Production - Historical\db\prod_history.accdb"
With myConnection
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Open "Data Source = """ & FilePath & """"
End With
Dim sSQL As String
sSQL = "SELECT [a_Field] FROM [a_Table] GROUP BY [a_Field];"
With myResults
.Source = sSQL
.ActiveConnection = myConnection
.CursorLocation = adUseClient
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Open
End With
varData = myResults.GetRows
Sheets("SHEET_1").myComboBox.List = Application.Transpose(varData)
myResults.Close
And here is the insert query i'd like to execute:
Code:
Dim sSQL As String
sSQL = "INSERT INTO [tblComments] ([WH_IDX], [CommentDate], [Comment], [User]) " _
& "VALUES (" & WH_KEY & "," & frmAddComment.txtDate.Value & "," & frmAddComment.txtComment.Value & "," & frmAddComment.txtUser.Value & ");"
Last edited: