create table in VBA and link to MDB with ODBC

MBMSOFT

Registered User.
Local time
Today, 13:40
Joined
Jan 29, 2010
Messages
90
I do create a new table and make a link to it with odbc , but the table is not updatable, i can only insert records, not delete or update

Function qqqq()

Dim A As Database
Dim b As QueryDef
Dim C As DAO.Recordset
Dim d As TableDef

On Error GoTo ERR_1
DoCmd.SetWarnings False
Set A = CurrentDb()
Set b = A.CreateQueryDef("qrytemp")

b.connect = "odbc;DSN=aaaaa;DATABASE=aaaaa;"
b.SQL = "CREATE TABLE newtable " & _
" (qa CHAR(6) ," & _
" qb CHAR(2) ," & _
" qc CHAR(8) )"

b.ReturnsRecords = True
Set C = b.OpenRecordset()
ERR_1:
Resume Next
CurrentDb.QueryDefs.delete "qryTemp"

Set d = A.CreateTableDef("newlink")
d.connect = "odbc;DSN=aaaaa;DATABASE=aaaaa;"
d.SourceTableName = "newtable"
A.TableDefs.Append d
Set C = A.OpenRecordset("newtable")
End Function
 
Since you are using ODBC, I will assume that you are NOT using an Access back end. I will assume that you are using some type of SQL server back end.

First: You must create a primary key for every table. To update or delete a record, you must specify the primary key to identify the record.

Your code does not appear to create a primary key field. Without a primary key, you will not be able to update or delete records.

You will need to modify your code to define a primary key.
 
thanks a lot... it.s working now ...
 

Users who are viewing this thread

Back
Top Bottom