johnmidcap
Programmer
Good evening. I am totally new to connecting to mySQL and have been trying to connect for a day now. I appreciate any guidance.
I have 5.1.6 and set this driver up on my computer. No problem connecting to the mySQL database.
I am trying to write VBA in an Excel spreadsheet that requires a user to enter a password, which is then verified against a mySQL db, before opening the spreadsheet. I am trying to connect using the following code:
Private Sub Worksheet_Activate ()
Dim sh1 As Sheet1
Dim SQL As String
Set conn = New ADODB.Connection ‘global variable
conn.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=IP; DATABASE=test;UID=test;PWD=test; OPTION=3" ‘IP and test is substituted for actual information
conn.open
Set sh1 = Excel.Worksheets(1)
Set rsCard = New ADODB.Recordset ‘global variable
SQL="select * from tblusers WHERE chrUser = ‘test’"
rsCard.CursorLocation = adUseServer
rsCard.Open SQL, conn
If Not rsCard.BOF
Sh1.Cells(0, 1).Value = rsCard. Fields(0)
End If
End Sub
I can access the mySQL db when setting up the link in User DSN and System DSB, but, when I run it I am getting an error that it cannot find the database. Any reason why this is happening?
Also, has anyone else used the above methodology to protect access to an Excel spreadsheet. The reason why I am trying this is because I do not want people that leave the organization to be able to use the spreadsheet. It is part of our IP.
Thanks for your assistance,
John
I have 5.1.6 and set this driver up on my computer. No problem connecting to the mySQL database.
I am trying to write VBA in an Excel spreadsheet that requires a user to enter a password, which is then verified against a mySQL db, before opening the spreadsheet. I am trying to connect using the following code:
Private Sub Worksheet_Activate ()
Dim sh1 As Sheet1
Dim SQL As String
Set conn = New ADODB.Connection ‘global variable
conn.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=IP; DATABASE=test;UID=test;PWD=test; OPTION=3" ‘IP and test is substituted for actual information
conn.open
Set sh1 = Excel.Worksheets(1)
Set rsCard = New ADODB.Recordset ‘global variable
SQL="select * from tblusers WHERE chrUser = ‘test’"
rsCard.CursorLocation = adUseServer
rsCard.Open SQL, conn
If Not rsCard.BOF
Sh1.Cells(0, 1).Value = rsCard. Fields(0)
End If
End Sub
I can access the mySQL db when setting up the link in User DSN and System DSB, but, when I run it I am getting an error that it cannot find the database. Any reason why this is happening?
Also, has anyone else used the above methodology to protect access to an Excel spreadsheet. The reason why I am trying this is because I do not want people that leave the organization to be able to use the spreadsheet. It is part of our IP.
Thanks for your assistance,
John