I have a form to add user.
I can add, delete rows in the table however I pretend to update if the user already exist.
My goal is press the row in sub form to edit.
but every time I press update it gives me an error.
Run-time error '3075' Syntax error operator in query expression.
the action code I have is this
Private Sub cmdAdd_Click()
'quando se carrega em Adicionar há 2 opcoes
'1-Insert
'2-Update
If Me.txtuserid.Tag & "" = "" Then
'1
CurrentDb.Execute "INSERT INTO user(userid, username, userfunction, usercc) " & _
" VALUES(" & Me.txtuserid & ",'" & Me.txtusername & "','" & Me.txtuserfun & "','" & Me.txtusercc & "')"
Else
'2
CurrentDb.Execute "UPDATE user " & _
" SET userid=" & Me.txtuserid & _
", username=" & Me.txtusername & "'" & _
", userfunction =" & Me.txtuserfun & "'" & _
", usercc =" & Me.txtusercc & "'" & _
" WHERE userid =" & Me.txtuserid.Tag
End If
'clear fields
cmdClear_Click
'refresh
SubForm1.Form.Requery
End Sub
What I'm doing wrong?
Did you miss ' in you update statement;
CurrentDb.Execute "UPDATE user " & _
" SET userid=" & Me.txtuserid & _
", username='" & Me.txtusername & "'" & _
", userfunction ='" & Me.txtuserfun & "'" & _
", usercc ='" & Me.txtusercc & "'" & _
" WHERE userid =" & Me.txtuserid.Tag
Related
Can you please tell me what is missing in the syntax below?
DoCmd.RunSQL "SELECT Val(Provisionsvertrag) as Provisions_vertrag,GarBeginn,GarEnde,GarReglNr as ORIGINAL_GarReglNr,right(GarBeginn,4)&mid(GarBeginn,4,2) AS VON, right(GarEnde,4)&mid(GarEnde,4,2) AS BIS, Verguetungsart,LEFT(Agenturinhabernr,4)&MID(Agenturinhabernr,6,4) as AGT8,Vertriebsweg, Garantiebetrag, [Garantiebtr waehr],Datediff('m',GarBeginn,GarEnde)+1 AS Anzahl_Monate INTO GARANTIE_TEMPOOO " & _
"FROM Garantie_Abzug " & _
"WHERE Garantie_Abzug.GarBeginn BETWEEN #" & Format(start_prv_year, "\#mm\/dd\/yyyy\#") & "# And #" & Format(end_rep_date, "\#mm\/dd\/yyyy\#") & "#"
I have recently inherited a DTS package written in VBScript, i have not had a lot of exposure to VBS and wanted to check if the function where i have added the ' Do i need a rs1.close here comment below should be closing the rs1 object before setting it again?.
Function Proc_Amend()
On error resume next
dtspackagelog.writestringtolog "Start Proc_Amend at " & Time
' Check record to be amended exists
set rs1 = cn1.execute("SELECT StatusFlag from wmLoadId where LoadID='" & iarray(1) & _
"' and OrderNumber='" & iarray(2) & "' and OrderLineNumber='" & iarray(4) & "' and OrderReleaseNumber='" & iarray(5) & "'")
If rs1.eof then
Err.Raise 9994 , , "Record to be amended DOES NOT exist"
Call ErrHand(err.number,err.description)
Else
If UCASE(rs1.fields("StatusFlag").value) = "PENDING" Then
iarray(14) = "PENDING"
End If
' Do i need a rs1.close here
set rs1 = cn1.execute("UPDATE wmLoadId set OrderWeight = " & iarray(9) & ",StatusFlag='" & iarray(14) & "',Timestamp = getdate() where LoadID='" & iarray(1) & _
"' and OrderNumber='" & iarray(2) & "' and OrderLineNumber='" & iarray(4) & "' and OrderReleaseNumber='" & iarray(5) & "'")
If Err Then
' An error occurred so process
Call ErrHand(err.number,err.description)
End If
' Check and update planned_ship_date (if reqd.)
' Do i need a rs1.close here
set rs1 = cn1.execute("SELECT planned_ship_date from Add_Info where LoadID='" & iarray(1) & _
"' and OrderNumber='" & iarray(2) & "' and OrderLineNumber='" & iarray(4) & "' and OrderReleaseNumber='" & iarray(5) & "'")
If rs1.eof then
Err.Raise 9988 , , "No Add_Info record exists to update"
Call ErrHand(err.number,err.description)
Else
cm.CommandText="select convert(varchar(10),wanted_delivery_date,103) AS PlanShip from OPENQUERY(DB33,'select wanted_delivery_date from CUSTOMER_ORDER_LINE_TAB where order_no=''" & iarray(2) & _
"'' and LINE_NO = ''" & iarray(4) & "'' AND REL_NO = ''" & iarray(5) & "'' ' ) "
dtspackagelog.writestringtolog "Planned_Ship_Date (amend) command is " & cm.CommandText
set rs = cm.execute()
dtspackagelog.writestringtolog "Err status after Planned_Ship_Date (amend) command is " & err.number & " at " & Time
if rs.eof then
On Error Resume Next
dtspackagelog.writestringtolog "No CUSTOMER_ORDER record found for order line (amend) at " & Time
Err.Raise 9987 , , "No CUSTOMER_ORDER record found for order line (amend) " & iarray(2) & " / " & iarray(4) & " / " & iarray(5)
Call ErrHand(err.number,err.description)
else
planship = rs.Fields("PlanShip").value
rs.close
End If
dtspackagelog.writestringtolog "PlanShip (amend) set to " & planship & " at " & Time
If rs1.fields("planned_ship_date").value <> planship Then
dtspackagelog.writestringtolog "Update PlanShip from " & rs1.fields("planned_ship_date").value & " to " & planship & " at " & Time
' Do i need a rs1.close here
set rs1 = cn1.execute("UPDATE Add_Info set planned_ship_date = '" & planship & "' where LoadID='" & iarray(1) & _
"' and OrderNumber='" & iarray(2) & "' and OrderLineNumber='" & iarray(4) & "' and OrderReleaseNumber='" & iarray(5) & "'")
If Err Then
' An error occurred so process
Call ErrHand(err.number,err.description)
End If
End If
End If
End If
dtspackagelog.writestringtolog "Finish Proc_Amend at " & Time
End Function
I'm trying to get the datareport working since dataflexgrid is already working, although I'm having a hard time passing the values to datareport, I can't even pass one please help thanks.
PS. all of them are in one form
Set mRS = New ADODB.Recordset
mRS.CursorLocation = adUseClient
mRS.CursorType = adOpenForwardOnly
mRS.LockType = adLockReadOnly
If mRS.State = 1 Then mRS.Close
mRS.Open "SHAPE {" & _
"SELECT " & _
"space(memberstree.level*6) + customer.description, " & _
"customer.customercode, " & _
"customer.remarks, " & _
"customer.membersince " & _
"From CUSTOMER " & _
"INNER JOIN memberstree on customer.customercode = memberstree.customercode " & xRootNode & " " & _
"ORDER by memberstree.pedigree + ltrim(str(memberstree.node,6,0))} AS rsCustomer " & _
"APPEND (( SHAPE {SELECT transactionNo, logdate, customercode, GrandTotal " & _
"From FinishedTransaction where " & xCriteria & "} AS rsTransaction " & _
"APPEND ({SELECT TransactionNo, Description, Qty From FinishedSales} As rsSales " & _
"RELATE TransactionNo TO TransactionNo))" & _
" RELATE customercode TO customercode)", gCNMark
mRS.Requery
Set MSHFlexGrid1.DataSource = mRS
I think this is the code that isn't working
With rptShape
Set .DataSource = mRS
.DataMember = ""
With .Sections("FinishedSales_Detail").Controls
.Item("txtDescription").DataMember = "rsSales"
.Item("txtDescription").DataField = "Description"
End With
.Show 1
It's ok now I have 3 TABLE with 2 SHAPE Command but in the data report I have 3 Group Header and supposed to be 2 as well.
I'm having an error message with my codes in visual basic. Please help. Thanks.
The error says:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
If Me.txtID.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO ProfessorListTable(ID,LastName,FirstName,MI,Gender,Department,ContactNo,Address,EmailAddress,YearEmployed)" & _
" VALUES(" & Me.txtID.Text & ",'" & Me.txtLName.Text & "','" & _
Me.txtFName.Text & "','" & Me.txtMI.Text & "','" & _
Me.txtGender.Text & "','" & Me.txtDept.Text & "','" & _
Me.txtNo.Text & "','" & Me.txtAddress.Text & "','" & _
Me.txtEAdd.Text & "','" & Me.txtYear.Text & "',')"
cmd.ExecuteNonQuery()
Else
cmd.CommandText = "UPDATE ProfessorListTable " & _
" SET txtID=" & Me.txtID.Text & _
", LastName='" & Me.txtLName.Text & "'" & _
", FirstName='" & Me.txtFName.Text & "'" & _
", MI='" & Me.txtMI.Text & "'" & _
", Gender='" & Me.txtGender.Text & "'" & _
", Department='" & Me.txtDept.Text & "'" & _
", ContactNo='" & Me.txtNo.Text & _
", Address='" & Me.txtAddress.Text & "'" & _
", EmailAddress='" & Me.txtEAdd.Text & "'" & _
", YearEmployed='" & Me.txtYear.Text & _
" WHERE stdid=" & Me.txtID.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
End Sub
The
You had extra Comma (,) here
& Me.txtYear.Text & "','
So it's leads to 11 value instead of 10
And Address is reserved word so use it as [Address]
Try like this
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim cmd As New OleDb.OleDbCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
If Me.txtID.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO ProfessorListTable(ID,LastName,FirstName,MI,Gender,Department,ContactNo,[Address],EmailAddress,YearEmployed)" & _
" VALUES(" & Me.txtID.Text & ",'" & Me.txtLName.Text & "','" & _
Me.txtFName.Text & "','" & Me.txtMI.Text & "','" & _
Me.txtGender.Text & "','" & Me.txtDept.Text & "','" & _
Me.txtNo.Text & "','" & Me.txtAddress.Text & "','" & _
Me.txtEAdd.Text & "','" & Me.txtYear.Text & "')"
cmd.ExecuteNonQuery()
Else
cmd.CommandText = "UPDATE ProfessorListTable " & _
" SET txtID=" & Me.txtID.Text & _
", LastName='" & Me.txtLName.Text & "'" & _
", FirstName='" & Me.txtFName.Text & "'" & _
", MI='" & Me.txtMI.Text & "'" & _
", Gender='" & Me.txtGender.Text & "'" & _
", Department='" & Me.txtDept.Text & "'" & _
", ContactNo='" & Me.txtNo.Text & _
", [Address]='" & Me.txtAddress.Text & "'" & _
", EmailAddress='" & Me.txtEAdd.Text & "'" & _
", YearEmployed='" & Me.txtYear.Text & _
" WHERE stdid=" & Me.txtID.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
End Sub
In my vb6 I am getting error 3704 operation is not allowed when object is closed.
I have search stackoverflow for similar problem but I think I'm missing something. I need to update every row in vfp based from recordset rs1 Here my code:
Option Explicit
Dim cn As New ADODB.Connection
Dim cn1 As New ADODB.Connection
Private Sub trns_Click()
Set cn = New ADODB.Connection
Set cn1 = New ADODB.Connection
cn.ConnectionString = MDI1.txtcn.Text
cn.Open
cn1.ConnectionString = "Provider=VFPOLEDB;Data Source=\\host1\software\MIL\company0"
cn1.Open
rs1.Open "Select * from trans", cn, adOpenStatic, adLockPessimistic
Do While Not rs2.EOF
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & ",Meal_allw = " & rs1.Fields("meal_allow") & ",on_duty = " & rs1.Fields("cnt") & ",no_d_local = " & rs1.Fields("local") & ",no_d_sick" _
& "= " & rs1.Fields("sick") & ",no_d_abs = " & rs1.Fields("absence") & ",no_d_spc = " & rs1.Fields("special") & ",Revenue02" _
& "= " & rs1.Fields("refund") & ",Revenue05 = " & rs1.Fields("prepay") & ",Deduct05 = " & rs1.Fields("prepay") & ",Revenue01 = " & rs1.Fields("comm") & "where code = '" & rs1.Fields("emp_code") & "' and transac.date = CTOD('" & trans.txtend2 & "')", cn1, adOpenDynamic, adLockPessimistic
If Not rs2.EOF Then
rs2.MoveNext
End If
Loop
rs2.close
Update query doesn't return recordset, hence your rs2 is not opened.
You perform your loop on the wrong recordeset : I replaced the some of the rs2 with rs1 in your code.
Do While Not rs1.EOF
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & ",Meal_allw = " & rs1.Fields("meal_allow") & ",on_duty = " & rs1.Fields("cnt") & ",no_d_local = " & rs1.Fields("local") & ",no_d_sick" _
& "= " & rs1.Fields("sick") & ",no_d_abs = " & rs1.Fields("absence") & ",no_d_spc = " & rs1.Fields("special") & ",Revenue02" _
& "= " & rs1.Fields("refund") & ",Revenue05 = " & rs1.Fields("prepay") & ",Deduct05 = " & rs1.Fields("prepay") & ",Revenue01 = " & rs1.Fields("comm") & "where code = '" & rs1.Fields("emp_code") & "' and transac.date = CTOD('" & trans.txtend2 & "')", cn1, adOpenDynamic, adLockPessimistic
If Not rs1.EOF Then
rs1.MoveNext
End If
Loop
rs1.close
You dont need to create a recordset to execute an update, insert or delete on the database. Just use the statement cn1.Execute YourSqlStatement where YourSqlStatement is the string you are passing on the rs2.Open instruction. The Execute method on the connection optionally accepts a byRef variable where you can get the number of records affected.
Example:
Dim nRecords As Integer
cn1.Execute "Update Table Set Field = Value Where AnotherField = SomeValue ", nRecords
MsgBox "Total Updated Records: " & Format(nRecords,"0")
try to open your rs2 before using if in the do while statement., or do it like this
rs2.open " blah blah blah "
Do Until rs2.eof
For Each fld In rs2.field
value_holder = fld.value
Next
rs2.movenext
Loop