kerveros2019
New member
- Local time
- Today, 01:07
- Joined
- Sep 25, 2019
- Messages
- 4
Hey everyone,
hope you guys can help me.
i have established a dao connection to my localhost (think so) and i am having problem creating a table in that database.
my problem is in this code:
Option Compare Database
Option Explicit
Dim db As Dao.Database
Dim rs As Dao.Recordset
Dim Conn As String
---------
Private Sub cmdTEST_Click()
'Create table and fields using DAO
Dim tdf As Dao.TableDef
Dim fldID As Dao.Field, fldName As Dao.Field
connectToDb
'Create the table definition
Set tdf = db.CreateTableDef("tblMsisdn")
'Create the field definitions
Set fldID = tdf.CreateField("ID", DataTypeEnum.dbLong)
fldID.Attributes = dbAutoIncrField
fldID.Required = False
Set fldName = tdf.CreateField("custName", DataTypeEnum.dbText)
fldName.AllowZeroLength = False
fldName.Required = False
'add the fields to the table
tdf.Fields.Append fldID
tdf.Fields.Append fldName
'add the table to the database
'db.TableDefs.Append tdf
'refresh the table and database
db.TableDefs.Refresh
Application.RefreshDatabaseWindow
Set fldID = Nothing
Set fldName = Nothing
Set tdf = Nothing
Set db = Nothing
Debug.Print "done"
End Sub
--------
Private Sub connectToDb()
Conn = "Driver={MariaDB ODBC 3.1 Driver};Server=localhost;UID=####;PWD=#####;DB=#####;Port=3306" 'Connection String to log into maria db using cretendials
Set db = OpenDatabase("", False, False, Conn) 'opens database from conn string, to use user prompt use "ODBC;" instead of conn
If Not db Is Nothing Then
MsgBox "Connected to zt-dbase"
End If
End Sub
i use debug and when i get to the point
db.TableDefs.Append tdf i get error run-time error 3146 odbc connection failed
Whereas if i do this.... (which is not exactly what i need)
Private Sub cmdExecute_Click()
Dim sql As String
connectToDb
On Error Resume Next
DoCmd.DeleteObject acTable, "ALLDBSTEST"
On Error GoTo 0
sql = "SELECT [dialer lists].FIXED INTO ALLDBSTEST FROM [dialer lists]"
Debug.Print sql
db.Execute sql
MsgBox "Created Table ALLDBSTEST"
db.Close
End Sub
it does create a new table named alldbstest on my server
hope you guys can help me.
i have established a dao connection to my localhost (think so) and i am having problem creating a table in that database.
my problem is in this code:
Option Compare Database
Option Explicit
Dim db As Dao.Database
Dim rs As Dao.Recordset
Dim Conn As String
---------
Private Sub cmdTEST_Click()
'Create table and fields using DAO
Dim tdf As Dao.TableDef
Dim fldID As Dao.Field, fldName As Dao.Field
connectToDb
'Create the table definition
Set tdf = db.CreateTableDef("tblMsisdn")
'Create the field definitions
Set fldID = tdf.CreateField("ID", DataTypeEnum.dbLong)
fldID.Attributes = dbAutoIncrField
fldID.Required = False
Set fldName = tdf.CreateField("custName", DataTypeEnum.dbText)
fldName.AllowZeroLength = False
fldName.Required = False
'add the fields to the table
tdf.Fields.Append fldID
tdf.Fields.Append fldName
'add the table to the database
'db.TableDefs.Append tdf
'refresh the table and database
db.TableDefs.Refresh
Application.RefreshDatabaseWindow
Set fldID = Nothing
Set fldName = Nothing
Set tdf = Nothing
Set db = Nothing
Debug.Print "done"
End Sub
--------
Private Sub connectToDb()
Conn = "Driver={MariaDB ODBC 3.1 Driver};Server=localhost;UID=####;PWD=#####;DB=#####;Port=3306" 'Connection String to log into maria db using cretendials
Set db = OpenDatabase("", False, False, Conn) 'opens database from conn string, to use user prompt use "ODBC;" instead of conn
If Not db Is Nothing Then
MsgBox "Connected to zt-dbase"
End If
End Sub
i use debug and when i get to the point
db.TableDefs.Append tdf i get error run-time error 3146 odbc connection failed
Whereas if i do this.... (which is not exactly what i need)
Private Sub cmdExecute_Click()
Dim sql As String
connectToDb
On Error Resume Next
DoCmd.DeleteObject acTable, "ALLDBSTEST"
On Error GoTo 0
sql = "SELECT [dialer lists].FIXED INTO ALLDBSTEST FROM [dialer lists]"
Debug.Print sql
db.Execute sql
MsgBox "Created Table ALLDBSTEST"
db.Close
End Sub
it does create a new table named alldbstest on my server