i'm having trouble forming the syntax to add a new row to a mysql database from ms access. i want to be able to check for duplicates then if no duplicates are there then add the new entry. this will be adding two text fields (full name and password). That's it.
any help would be appreciated.
Here is my code i have within a click event to add record:
Private Sub Add_Button_Click()
' check if needed fields are blank
If (IsNull(Full_Name_Text)) Then
msgbox ("Please enter a Full Name"), vbOKOnly, "Data Missing"
Else
If (IsNull(Password_Text)) Then
msgbox ("Please enter a Password"), vbOKOnly, "Data Missing"
Else
' connect via the mysql-connector-odbc-5.1.5-win32.msi file/driver...
Dim MySQLConn, sqlstr, MyRS, c
Set MySQLConn = CreateObject("ADODB.Connection")
MySQLConn.Open = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;DATABASE=mechanicdatabase;USER=****;PASSWORD=****;OPTION=3;"
sqlstr = "select * from mechanicdatabase;"
Set MyRS = MySQLConn.Execute(sqlstr)
Dim strPassword As String
Set NameCheck = CurrentDb.OpenRecordset("SELECT mechanicdatabase.* FROM mechanicdatabase WHERE mechanicdatabase.[Full Name]='" & Me.Password_Text.value & "';", 2)
If NameCheck.EOF Then
'send to md5 code for digesting
strPassword = DigestStrToHexStr(Me.Password_Text.value)
'verification of digesting, delete after testing of code is done
msgbox strPassword, vbOKOnly, "test"
CurrentDb.OpenRecordset ("INSERT INTO mechanicdatabase([Full Name], Password) Values(@[Full Name],'" & strPassword & "'")
'I don't think the above is correct. i did a little programming in vb.net and
'this insert statement just doesn't look right. it's probably something really
'simple.
On Error GoTo Err_Add_Button_Click
DoCmd.GoToRecord , , acNewRec
Exit_Add_Button_Click:
Exit Sub
Err_Add_Button_Click:
msgbox Err.Description
Resume Exit_Add_Button_Click
End Sub
any help would be appreciated.
Here is my code i have within a click event to add record:
Private Sub Add_Button_Click()
' check if needed fields are blank
If (IsNull(Full_Name_Text)) Then
msgbox ("Please enter a Full Name"), vbOKOnly, "Data Missing"
Else
If (IsNull(Password_Text)) Then
msgbox ("Please enter a Password"), vbOKOnly, "Data Missing"
Else
' connect via the mysql-connector-odbc-5.1.5-win32.msi file/driver...
Dim MySQLConn, sqlstr, MyRS, c
Set MySQLConn = CreateObject("ADODB.Connection")
MySQLConn.Open = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;DATABASE=mechanicdatabase;USER=****;PASSWORD=****;OPTION=3;"
sqlstr = "select * from mechanicdatabase;"
Set MyRS = MySQLConn.Execute(sqlstr)
Dim strPassword As String
Set NameCheck = CurrentDb.OpenRecordset("SELECT mechanicdatabase.* FROM mechanicdatabase WHERE mechanicdatabase.[Full Name]='" & Me.Password_Text.value & "';", 2)
If NameCheck.EOF Then
'send to md5 code for digesting
strPassword = DigestStrToHexStr(Me.Password_Text.value)
'verification of digesting, delete after testing of code is done
msgbox strPassword, vbOKOnly, "test"
CurrentDb.OpenRecordset ("INSERT INTO mechanicdatabase([Full Name], Password) Values(@[Full Name],'" & strPassword & "'")
'I don't think the above is correct. i did a little programming in vb.net and
'this insert statement just doesn't look right. it's probably something really
'simple.
On Error GoTo Err_Add_Button_Click
DoCmd.GoToRecord , , acNewRec
Exit_Add_Button_Click:
Exit Sub
Err_Add_Button_Click:
msgbox Err.Description
Resume Exit_Add_Button_Click
End Sub
Last edited: