I have one more problem i was hoping to get solved today
I am using this code to create a new table in my mysql database:
This code is working, but forces me to have some text infront of the name of the new table name. So when H1 = 123 the new table name is P123.
I have tried using
table1 = Range("H1").Value ' give me a System Error &H80040E14 (-2147217900)
table1 = "" & Range("H1").Value ' gives me the same System Error
and i cant use numbers either if i could have a standard first number.
table1 = "1" & Range("H1").Value ' same System Error
table1 = 1 & Range("H1").Value ' same System Error
What am i doing wrong? I only want the new table name to be the numbers in H1.
Thx in advance for any view or reply!
I am using this code to create a new table in my mysql database:
Code:
Sub excelmysql()
' Connection variables
Dim conn As New ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
' Table action variables
Dim i As Long ' counter
Dim SQLStr As String ' SQL to perform various actions
Dim table1 As String
Dim field1 As String, field2 As String
Dim rs As ADODB.Recordset
Dim vtype As Variant
Server_Name = "127.0.0.1" ' Enter your server name here - if running from a local computer use 127.0.0.1
Database_Name = "my_database" ' Enter your database name here
User_ID = "root" ' enter your user ID here
Password = "mypass" ' Enter your password here
Set conn = New ADODB.Connection
conn.Open "DRIVER={MySQL ODBC 5.1 Driver}" _
& ";SERVER=" & Server_Name _
& ";DATABASE=" & Database_Name _
& ";UID=" & User_ID _
& ";PWD=" & Password _
& ";OPTION=16427"
vtype = Array("varchar(255)", "Text", "LongText", "Int(10)", "Float", "Double", "Date", "Time") ' array of commonly used MySQL variable types
table1 = "P" & Range("H1").Value
field1 = "field1text"
field2 = "field2text"
SQLStr = "CREATE TABLE " & table1 & "(" _
& field1 & " " & vtype(0) & "," _
& field2 & " " & vtype(4) _
& ")"
conn.Execute SQLStr
On Error Resume Next
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
On Error GoTo 0
End Sub
I have tried using
table1 = Range("H1").Value ' give me a System Error &H80040E14 (-2147217900)
table1 = "" & Range("H1").Value ' gives me the same System Error
and i cant use numbers either if i could have a standard first number.
table1 = "1" & Range("H1").Value ' same System Error
table1 = 1 & Range("H1").Value ' same System Error
What am i doing wrong? I only want the new table name to be the numbers in H1.
Thx in advance for any view or reply!