Can anyone help me with the below code to edit the records please?Im trying to edit but there is a Syntax error and I cant fix that.
See the error that appears below.
Run Time Error '3075'
Syntax Error(missing operator) in query expresion 'TypeID='.
Thanks
Private Sub oshaadd_Click()
'On Error Resume Next
If (IsNull(Me.oshaID) Or (Me.oshaID = "") And IsNull(Me.oshatype) Or (Me.oshatype = "")) Then
MsgBox "please fill required fields!", vbInformation, "Information"
Exit Sub
End If
If Me.oshaID.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO osha(TypeID, OSHA)" & _
"VALUES ('" & Me.oshaID & "', '" & Me.oshatype & "')"
If MsgBox("Added", vbOKOnly) Then
Me.osha_subform.Form.Requery
End If
Else
CurrentDb.Execute "UPDATE osha " & _
"SET TypeID =" & Me.oshaID & _
", OSHA = '" & Me.oshatype & "'" & _
"WHERE TypeID =" & Me.oshatype.Tag
MsgBox "Updated", vbInformation, "Information"
Me.oshaadd.Caption = "Add"
Me.oshaedit.Enabled = True
End If
Me.osha_subform.Form.Requery
End Sub
Private Sub oshaedit_Click()
On Error Resume Next
If Not (Me.osha_subform.Form.Recordset.EOF And Me.osha_subform.Form.Recordset.BOF) Then
With Me.osha_subform.Form.Recordset
Me.oshaID = .Fields("TypeID")
Me.oshatype = .Fields("OSHA")
Me.oshaID.Tag = .Fields("TypeID")
Me.oshaadd.Caption = "Update"
Me.oshaedit.Enabled = False
End With
End If
End Sub
You forget to put the database single quote around Me.oshaID and Me.oshatype.Tag in the UPDATE SQL statement:
CurrentDb.Execute "UPDATE osha " & _
"SET TypeID ='" & Me.oshaID & "'" & _
", OSHA = '" & Me.oshatype & "'" & _
" WHERE TypeID ='" & Me.oshatype.Tag &"';"
CurrentDb.Execute "UPDATE osha " & _
"SET TypeID =" & Me.oshaID & _
", OSHA = '" & Me.oshatype & "'" & _
"WHERE TypeID =" & Me.oshatype.Tag
MsgBox "Updated", vbInformation, "Information"
Me.oshaadd.Caption = "Add"
Me.oshaedit.Enabled = True
In this block of your code where you have "SET TypeID =" and "WHERE TypeID =" try adding a space after the equals sign so it reads "TypeID = ". If that doesn't resolve the error try adding single quotes around the value you are assigning to TypeID (TypeID = '" & Me.oshaID & _"',)
Related
Good Day! I'm clueless on visual studio. Please Help me.
I have a datagridview that has database access file.
its bound to textboxes
now i have a search button that has a textbox too.
it runs fine but it needs to input the complete name.
I want it to be when you just input a letter it shows all the names that has/have that letter.
for example if i type "A" all names in the the database that has letter "A" on it will show.
but in this case
if i type "AGING" it will say cant find. It must be "AGING OVEN" for it to show the result.
here is my code.
please help thanks
Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBtn.Click
On Error GoTo SearchErr
If SearchTxtbox.Text = "" Then
Exit Sub
Else
Dim cantFind As String = SearchTxtbox.Text
TOOLSANDEQUIPMENTBindingSource.Filter = "(CONVERT(ID, 'System.String') like '" & SearchTxtbox.Text & "')" & _
"OR ([TOOL and EQUIPMENT] like '" & SearchTxtbox.Text & "') OR ([QUANTITY] like '" & SearchTxtbox.Text & "')" & _
"OR ([ITEM NO] like '" & SearchTxtbox.Text & "')" & _
"OR ([PART NO] like '" & SearchTxtbox.Text & "')" & _
"OR ([DATE MODIFIED] like '" & SearchTxtbox.Text & "')"
If TOOLSANDEQUIPMENTBindingSource.Count <> 0 Then
With TEDataGridView
.DataSource = TOOLSANDEQUIPMENTBindingSource
End With
Else
MsgBox("--> " & cantFind & vbNewLine & _
"The search item was not found.", _
MsgBoxStyle.Information, "Hey Boss!")
TOOLSANDEQUIPMENTBindingSource.Filter = Nothing
With TEDataGridView
.ClearSelection()
.ReadOnly = True
.MultiSelect = False
.DataSource = TOOLSANDEQUIPMENTBindingSource
End With
End If
End If
ErrEx:
Exit Sub
SearchErr:
MsgBox("Error Number " & Err.Number & vbNewLine & _
"Error Description " & Err.Description, MsgBoxStyle.Critical, _
"Reser Error!")
Resume ErrEx
End Sub
I keep recieving compiling errors saying that txtlln in the where line cannot be found. I am fairly new to SQL/VBA so I am not sure I am using the correct expressions to have this work.
Private Sub btnlledit_Click()
Dim strSQL As String
SQL = "UPDATE tblll " & _
"SET [Component/Product] = '" & Forms!frmaddll!txtllcomponent & "',[HN] = '" & Forms!frmaddll!txtllhn & "' " & _
"WHERE [LLN] = '" & Forms!frmaddll!txtlln.value & "';"
debug.print sql
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
DoCmd.Requery
Me.Refresh
End Sub
You seem to have a few issues swith your string concatenation.
Private Sub btnlledit_Click()
Dim strSQL As String
SQL = "UPDATE tblll " & _
"SET [Component/Product] = '" & Forms!frmaddll!txtllcomponent & "' " & _
"WHERE [LLN] = '" & Forms!frmaddll!txtlln.value & "';"
debug.print sql
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
DoCmd.Requery
Me.Refresh
End Sub
I am attempting to write an UPDATE function based on values that will be input into dropdown boxes and text boxes by a user
My code is as follows:
Private Sub cmdUpdate_Prices_Click()
Dim SQL_string As String
SQL_string = _
"UPDATE tblPrice " & _
"SET [P/N] = " & Me.txtPartNumber.Column(0) & ", " & _
"Type = " & Me.txtPriceType.Column(0) & ", " & _
"Region = " & Me.txtRegion.Column(0) & ", " & _
"Price = " & Me.txtPrice.Value & ", " & _
"WHERE ID = " & Me.txtID.Value & ";"
DoCmd.RunSQL SQL_string
End Sub
I keep getting a syntax error in the UPDATE function and I'm not sure where it is.
Any help is appreciated. Thanks!
In Access 2010 I have tables, e.g. Employee(Pracownicy). I can update the data in the table using the subform and the update button.
Updating the data in the subform automatically generates an Outlook mail containing the data in the updated record.
I need to change font color for updated data in the mail body.
The code to update the data and generate e-mail:
Private Sub cmdUpdate2_Click()
CurrentDb.Execute "update Pracownicy" & _
" SET Identyfikator='" & Me.txtID & "'" & _
", Imie='" & Me.txtImie & "'" & _
", Nazwisko ='" & Me.txtNazwisko & "'" & _
", Wiek ='" & Me.txtWiek & "'" & _
", Data_urodzenia ='" & Me.txtData & "'" & _
", Miejsce_urodzenia ='" & Me.txtMiejsce & "'" & _
", Miejscowosc ='" & Me.txtMiejscowosc & "'" & _
", Plec ='" & Me.txtPlec & "'" & _
" where Identyfikator='" & Me.txtID & "'"
'------------------------------------SEND EMAIL----------------------
'Dim varName As Variant
'Dim strUCC As String
Dim varSubject As Variant
Dim varBody As Variant
Dim Poczta As Object
Dim MojMail As Object
On Error Resume Next
'varName = ""
varSubject = "Employer List "
varBody = "Hello" & _
"<br><br>Employer List: " & _
"<br><br><B>Identyfikator:</B> " & Me.txtID & " " & _
"<br><B>Imie:</B> " & Me.txtImie & " " & _
"<br><B>Nazwisko:</B> " & Me.txtNazwisko & " " & _
"<br><B>Wiek:</B> " & Me.txtWiek & " " & _
"<br><B>Data urodzenia:</B> " & Me.txtData & " " & _
"<br><B>Miejsce urodzenia:</B> " & Me.txtMiejsce & " " & _
"<br><B>Miejscowosc:</B> " & Me.txtMiejscowosc & " " & _
"<br><B>Plec:</B> " & Me.txtPlec & " "
Set Poczta = CreateObject("outlook.application")
Set MojMail = Poczta.createitem(0)
With MojMail
'.To =
'.BCC =
.subject = varSubject
'.ReadReceiptRequested = True
'.originatorDeliveryReportRequested = True
.htmlbody = varBody & "<br>"
.display
'.send
End With
Set Poczta = Nothing
Set MojMail = Nothing
If Err.Number <> 0 Then
MsgBox ("Atention")
End If
On Error GoTo 0
'------------------------------------------------------------------------
DoCmd.Close
MsgBox ("End Update")
End Sub
I think this becomes more of an HTML question rather than VBA. Try adding a FONT tag to the following line and see if that works for you.
"<br><br><B><font color="red">Identyfikator:</font></B> " & Me.txtID & " " & _
I have a large form with multiple functions, one of the functions is to edit a subform that houses a list of codes and other various pieces of data. When I click the edit button it auto fills the boxes with the selected data, but when I make the edits and try and save it i get the error message: RUN TIME ERROR 3075 SYNTAX ERROR (MISSING OPERATOR) IN QUERY EXPRESSION
The whole code is
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. For insert
'2. For Update
If Me.txt_code.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO KWTable(KW, Source, Code) " & _
" VALUES('" & Me.text_key & "','" & Me.combo_source & "','" & _
Me.txt_code & "')"
Else
'otherwise (Tag of txtID store the id of student to be modified)
CurrentDb.Execute "UPDATE KWTable " & _
" SET KW='" & Me.text_key & _
", Code='" & Me.txt_code & "'" & _
", Source='" & Me.combo_source & "'" & _
" WHERE KW='" & Me.text_key
End If
'clear form
cmdClear_Click
'refresh data in list on form
TableSub.Form.Requery
End Sub
And the portion that is highlighted when I try and debug the issue is.
CurrentDb.Execute "UPDATE KWTable " & _
" SET KW='" & Me.text_key & _
", Code='" & Me.txt_code & "'" & _
", Source='" & Me.combo_source & "'" & _
" WHERE KW='" & Me.text_key
Try
CurrentDb.Execute "UPDATE KWTable " & _
" SET KW='" & Me.text_key & _
"', Code='" & Me.txt_code & "'" & _
", Source='" & Me.combo_source & "'" & _
" WHERE KW='" & Me.text_key + "'"