R
RyGuy
Using Access 2007. I have a reference to the following:
OLE Automation
Microsoft Office 12.0 Object Library
Microsoft ActiveX data Objects 2.8 Library.
I’m trying to add data from a form to a table. I’ve been experimenting with
a few versions of this code for a few days now. Still struggling.
Private Sub Post_Click()
Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstPatientTable As ADODB.Recordset
Dim strCnn As String
'Dim mydb As DAO.Database
Dim mydb As String
'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\Pivot Trading System.accdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
'On Error GoTo S:
cnn1.Open strCnn
' Open contact table.
Set rstcontact = New ADODB.Recordset
rstcontact.CursorType = adOpenKeyset
rstcontact.LockType = adLockOptimistic
rstcontact.Open "Options", cnn1, , , adCmdTable
'get the new record data
rstcontact.AddNew
'rstcontact!OptionsNo = OptionsNo
rstcontact!TicketNo = TicketNo
rstcontact!Side = Side
rstcontact!Symbol = Symbol
rstcontact!Quantity = Quantity
rstcontact!Strike = Strike
rstcontact!Call_Put = Call_Put
rstcontact!Price = Price
rstcontact!Exchange = Exchange
rstcontact!Approved = Approved
rstcontact!DateAdd = Now()
rstcontact.Update
' Show the newly added data.
MsgBox "New Post: " & rstcontact!TicketNo & " " & rstcontact!Symbol & " has
been successfully added"
'close connections
rstcontact.Close
Else
MsgBox "An Error has occurred, please check and try again"
End If
End Sub
Code errors here:
cnn1.Open strCnn
Error message is:
Unrecognized database format ‘C:\Pivot Trading System.accdb’
I never had any errors with this code in Access 2003. Now, in 2007, nothing
but errors.
Any ideas?
Thanks!
Ryan---
OLE Automation
Microsoft Office 12.0 Object Library
Microsoft ActiveX data Objects 2.8 Library.
I’m trying to add data from a form to a table. I’ve been experimenting with
a few versions of this code for a few days now. Still struggling.
Private Sub Post_Click()
Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstPatientTable As ADODB.Recordset
Dim strCnn As String
'Dim mydb As DAO.Database
Dim mydb As String
'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\Pivot Trading System.accdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
'On Error GoTo S:
cnn1.Open strCnn
' Open contact table.
Set rstcontact = New ADODB.Recordset
rstcontact.CursorType = adOpenKeyset
rstcontact.LockType = adLockOptimistic
rstcontact.Open "Options", cnn1, , , adCmdTable
'get the new record data
rstcontact.AddNew
'rstcontact!OptionsNo = OptionsNo
rstcontact!TicketNo = TicketNo
rstcontact!Side = Side
rstcontact!Symbol = Symbol
rstcontact!Quantity = Quantity
rstcontact!Strike = Strike
rstcontact!Call_Put = Call_Put
rstcontact!Price = Price
rstcontact!Exchange = Exchange
rstcontact!Approved = Approved
rstcontact!DateAdd = Now()
rstcontact.Update
' Show the newly added data.
MsgBox "New Post: " & rstcontact!TicketNo & " " & rstcontact!Symbol & " has
been successfully added"
'close connections
rstcontact.Close
Else
MsgBox "An Error has occurred, please check and try again"
End If
End Sub
Code errors here:
cnn1.Open strCnn
Error message is:
Unrecognized database format ‘C:\Pivot Trading System.accdb’
I never had any errors with this code in Access 2003. Now, in 2007, nothing
but errors.
Any ideas?
Thanks!
Ryan---