EDIT Error Formula (VBA)

Jerome_RA

Board Regular
Joined
Dec 26, 2016
Messages
53
Office Version
  1. 2013
Platform
  1. Windows
Hello Excel Masters,

I need help in regards to my work. I am trying to create a EDIT Querry to be connected to MS Access but it seems my code won't push thru. The Save and Delete button of my work is already done. I just need the EDIT button to work.

Here is my code. (it will be getting a syntax error (-2147217900 (80040e14) on the highlighted part below "red")

====



Private Sub cmdEdit_Click()




If txtEmployeeID.Text = "" Then
MsgBox "Nothing to Edit", vbInformation, "Tracker"
Else




Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnn.Open "Provider=Microsoft.ace.OLEDB.12.0;" & _
"Data Source=D:\EXCEL\MasterlistDB.mdb"

Set rst = New ADODB.Recordset


rst.Open "SELECT * FROM TMasterlist;", _
cnn, adOpenStatic

strsql = "update TMasterlist set CompleteName = '" & txtName.Text _
& "', LOB = '" & txtLOB.Text _
& "', Position = '" & txtPosition.Text _
& "', Supervisor = '" & txtSupervisor.Text _
& "', Manager = '" & txtManager.Text _
& "' where EmployeeID = '" & txtEmployeeID.Text & "'"




Set cmd = New ADODB.Command
cmd.CommandText = strsql
cmd.ActiveConnection = cnn
cmd.Execute


rst.Close
cnn.Close




End If






End Sub
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Forgot to add Functions from the Code. Here it is below. Really having a hard time figuring this out why I cannot update the records from my database.

------------------------------------

Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Public cmd As ADODB.Command
Public strsql As String

Private Sub cmdEdit_Click()

If txtEmployeeID.Text = "" Then
MsgBox "Nothing to Edit", vbInformation, "Tracker"
Else

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnn.Open "Provider=Microsoft.ace.OLEDB.12.0;" & _
"Data Source=D:\EXCEL\MasterlistDB.mdb"

Set rst = New ADODB.Recordset


rst.Open "SELECT * FROM TMasterlist;", _
cnn, adOpenStatic

strsql = "update TMasterlist set CompleteName = '" & txtName.Text _
& "', LOB = '" & txtLOB.Text _
& "', Position = '" & txtPosition.Text _
& "', Supervisor = '" & txtSupervisor.Text _
& "', Manager = '" & txtManager.Text _
& "' where EmployeeID = '" & txtEmployeeID.Text & "'"

Set cmd = New ADODB.Command
cmd.CommandText = strsql
cmd.ActiveConnection = cnn
cmd.Execute


rst.Close
cnn.Close


End If

End Sub
 
Upvote 0
Hi All,

Want to update that I already figured it out.

Thank you. :)
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top