mrmmickle1
Well-known Member
- Joined
- May 11, 2012
- Messages
- 2,461
I am trying to do several things in this procedure:
1. Delete an existing table.
2. Then create a new table.
3. Then write records to the table
I have been successful with the first two items however, I am getting a Run Time Error 3001 Application Defined or Object Defined Error on the red line when I try to open the table to input the records. Any help resolving this problem would be great.
Thanks for taking the time to look at this for me.
1. Delete an existing table.
2. Then create a new table.
3. Then write records to the table
I have been successful with the first two items however, I am getting a Run Time Error 3001 Application Defined or Object Defined Error on the red line when I try to open the table to input the records. Any help resolving this problem would be great.
Code:
[COLOR=#0000ff]Public Sub[/COLOR] AccessTableUpdate()
[COLOR=#0000ff]Dim[/COLOR] CurrentAccessDB [COLOR=#0000ff]As String[/COLOR]
[COLOR=#0000ff]Dim [/COLOR]adoRecSet [COLOR=#0000ff] As Object[/COLOR][COLOR=#008000] 'As New ADODB.Recordset[/COLOR]
[COLOR=#0000ff]Dim[/COLOR] connDB [COLOR=#0000ff] As Object [/COLOR]'[COLOR=#008000]As New ADODB.Connection[/COLOR]
[COLOR=#0000ff] Dim[/COLOR] rng [COLOR=#0000ff]As[/COLOR] Range
[COLOR=#0000ff]Dim[/COLOR] i [COLOR=#0000ff]As Long[/COLOR]
[COLOR=#0000ff] Dim[/COLOR] lFieldCount [COLOR=#0000ff]As Long[/COLOR]
[COLOR=#0000ff]Dim[/COLOR] strSql [COLOR=#0000ff]As String[/COLOR]
CurrentAccessDB = "C:\Users\mmickle\Desktop\PCLS_Master_Review_Database.mdb"
[COLOR=#0000ff] Set[/COLOR] connDB = CreateObject("ADODB.Connection")
connDB.Open ConnectionString:="Provider = Microsoft.ACE.OLEDB.12.0; data source=" & CurrentAccessDB
[COLOR=#0000ff] Set[/COLOR] adoRecSet = CreateObject("ADODB.Recordset")
[COLOR=#008000] 'Delete Old Locations Table[/COLOR]
connDB.Execute "DROP TABLE Locations;"
[COLOR=#008000] 'Create New Table[/COLOR]
strSql = vbNullString
strSql = "CREATE TABLE Locations([Address_1] TEXT(200)"
strSql = strSql & vbLf & ", [Address_2] TEXT(200)"
strSql = strSql & vbLf & ", [Address_City] TEXT(50)"
strSql = strSql & vbLf & ", [Address_Email] TEXT(75)"
strSql = strSql & vbLf & ", [Address_State] TEXT(2)"
strSql = strSql & vbLf & ", [Address_Zip] TEXT(25)"
strSql = strSql & vbLf & ", [ID] TEXT(12)"
strSql = strSql & vbLf & ", [Name_Location] TEXT(200)"
strSql = strSql & vbLf & ", [Name_Location_Short] TEXT(200)"
strSql = strSql & vbLf & ", [Number_Fax] TEXT(25)"
strSql = strSql & vbLf & ", [Number_Pager] TEXT(25)"
strSql = strSql & vbLf & ", [Number_Phone_Cell] TEXT(25)"
strSql = strSql & vbLf & ", [Number_Phone_Home] TEXT(25)"
strSql = strSql & vbLf & ", [Flag_Status] TEXT(25)"
strSql = strSql & vbLf & ", [Number_Phone_Work] TEXT(25)"
strSql = strSql & vbLf & ", [Flag_AutoFax] TEXT(200)"
strSql = strSql & vbLf & ", [Location_Account] TEXT(200)"
strSql = strSql & vbLf & ", [Timestamp_Creation] DATETIME"
strSql = strSql & vbLf & ", [Notes] TEXT(255));"
connDB.Execute strSql
[B][COLOR=#ff0000] adoRecSet.Open "Locations", connDB, adOpenKeyset, adLockOptimistic, adCmdTable 'Open Table
[/COLOR][/B] [COLOR=#008000] 'Code to write records here.....[/COLOR]
Thanks for taking the time to look at this for me.