I have a vb6 project and i need to update a visual foxpro table from a recordset.My issue is when i try to update the table i get error msg:Command contains unregnized phrase/keywords.My problem is situated where the date field is concern.I dont know if i written the last portion of the code right.Here is my code:
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") & "where code = '" & rs1.Fields("emp_code") & "and transac.date = & trans.txtend &", cn1, adOpenDynamic, adLockPessimistic
Try this:
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") & " where code = '" & rs1.Fields("emp_code") & "' and transac.date = '" & trans.txtend &"'", cn1, adOpenDynamic, adLockPessimistic
It looks like you were missing a space before the WHERE keyword and you missed a single-quote after emp_code. It also looks like you had a problem with transac date.
If the solution from G Mastros is still not complete, it may be due to incorrect data type of a "Date" field. you may need to change to
transac.date = CTOD('" & trans.txtend &"') "
as if you are sending in a text string, but the date is of a DATE type field, you'll need to have it converted to a VFP recognized function... CTOD() is Convert Character String to a Date.
Related
I am trying to update my Table (Referral) Field name (referdate) type Date
to be updated by using inputbox, where the user pass the number through the input box and then to this number to referdate to give me date + 2 days result. (example: inputbox 2 days, add 2 days to 20-12-2020 result is 22-12-2020)
the error I get (syntax error in the update statement)
my access version is 2013
my code below:
Dim S As Integer
S = InputBox(" How many days to follow", "Number of Days !")
DoCmd.RunSQL "UPDATE Referral" & _
"SET referdate = referdate" & Me.referdate + S & _
"where SRSno = " & Me.SRSno
Me.Refresh
According to the docs (https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/update-statement-microsoft-access-sql), it seems that your statement might be including the existing column value being concatenated with the local variable.. Try this:
DoCmd.RunSQL "UPDATE Referral" & _
"SET referdate = " & Me.referdate + S & _
"where SRSno = " & Me.SRSno
The difference is subtle, but the Microsoft example shows adding a value as part of the query expression to the existing column value:
SET OrderAmount = OrderAmount * 1.1,
The alternative syntax for your case might be:
DoCmd.RunSQL "UPDATE Referral" & _
"SET referdate = referdate + " & S & _
"where SRSno = " & Me.SRSno
In either case, notice that referdate only appears once in the statement.
Include DateAdd and don't forget the spaces:
If Val(S) > 0 Then
DoCmd.RunSQL "UPDATE Referral " & _
"SET referdate = DateAdd('d', " & Val(S) & ", referdata) " & _
"WHERE SRSno = " & Me.SRSno & ""
End If
I have a VBscript that queries the database to pull data out that is based on the shift e.g. graveyard, day, and swing. I need to adjust the time by an hour less only on days that are past 1-6-2019.
The solution I have tried is expanding my if statement and adding an AND function but it won't work because the first if statement is still true.
dim intCoilCount, intTotalSeconds,intSeconds,strDate,strShift
'SQL="select timeStamp, coil_number, entry_gaptime,thickness,width_in,grade from TABLEEEE by timeStamp"
strShift=Request.Form("SHIFT")
strDate=Request.Form("StartDate")
'if date is greater than 2-22-2006 (switchover date) use SCALEFACTOR
'-----start-----------------
if datediff("d",strDate,cdate("2/22/2006")) <= 0 then
SCALEFACTOR=30000.0 / 50.0
else
SCALEFACTOR=1
end if
'-----end-----------------
'Fixed scale factor problem
'-----start-----------------
SCALEFACTOR=1
'-----end-----------------
SQL="select timeStamp, coil_number, entry_gaptime,thickness,width_in,grade from entryCoilData"
if strShift="graveyard" then
SQL = SQL & " where timestamp > '" & cdate(strDate)-1 & " " & "11:00PM" & "'" & _
" and timestamp <= '" & strDate & " " & "7:00AM" & "'"
elseif strShift="graveyard" and strDate >= cdate(1-6-2019) then
SQL = SQL & " where timestamp > '" & strDate & " " & "10:00AM" & "'" & _
" and timestamp <= '" & strDate & " " & "2:00PM" & "'"
elseif strShift="day" then
SQL = SQL & " where timestamp > '" & strDate & " " & "7:00AM" & "'" & _
" and timestamp <= '" & strDate & " " & "3:00PM" & "'"
elseif strShift="day" and strDate >= cdate(1-6-2019) then
SQL = SQL & " where timestamp > '" & strDate & " " & "7:00AM" & "'" & _
" and timestamp <= '" & strDate & " " & "3:00PM" & "'"
else
SQL = SQL & " where timestamp > '" & strDate & " " & "3:00PM" & "'" & _
" and timestamp <= '" & strDate & " " & "11:00PM" & "'"
end if
I would keep that pesky logic out of the SQL string, and do that in vbscript. Something like this (untested):
dim givendate, startdatetime, enddatetime
givendate = cdate(strDate)
startdatetime = CDate(strDate & " " & "3:00PM")
enddatetime = CDate(strDate & " " & "11:00PM")
if strShift="graveyard" then
if givendate >= cdate("1-6-2019") then
startdatetime = CDate(strDate & " " & "10:00AM")
enddatetime = CDate(strDate & " " & "02:00PM")
else
startdatetime = DateADD("d", -1, CDate(strDate & " " & "11:00PM"))
enddatetime = CDate(strDate & " " & "07:00AM")
end if
end if
if strShift="day" then
startdatetime = CDate(strDate & " " & "07:00PM")
enddatetime = CDate(strDate & " " & "03:00PM")
end if
SQL="SELECT timeStamp, coil_number, entry_gaptime,thickness,width_in,grade from entryCoilData"
SQL = SQL & " WHERE timestamp > '" & startdatetime & "'"
SQL = SQL & " AND timestamp <= '" & enddatetime & "'"
response.write(SQL)
This way you just calculate the startdatetime and enddatetime parameters, and execute the same SQL for each case.
Please note that the way you write your SQL statements in ASP leaves you vulnerable to SQL injection attacks.
You might also want to consider writing date strings in ISO format (yyyy-mm-dd), that way the database will always understand the date. When you use cdate("1-6-2019"), this might be june first or january sixth, depending on how your database or OS is configured. When you use cdate("2019-6-1"), this is universally understood as june first.
Getting this error out of an old VB6 app that I've been presented with updating. So I got XP Mode up and running and VB6 installed and updated on it and I've added the menu option that was requested of me, but now I'm getting this error.
There are several examples of this error or similar here on SO and I looked through a bunch of them, but the circumstances aren't exactly the same and I'm still a pretty newbie developer and I just need help. I tested the query I wrote on our dev server and the VB syntax around it, that part is working fine. I think it has something to do with the result set logic near the end:
Private Sub FillDoor()
Dim m_rsDoor As ADODB.Recordset
cboDoorStyle.Clear
Set m_rsDoor = conSQL.Execute("SELECT bpm.[Description] " & _
"FROM tblBrandProductMaster bpm " & _
"INNER JOIN tblDoorStyles ds " & _
"ON ds.DoorStyleCode = bpm.Code " & _
"INNER JOIN tblFamilyDoorStyles fds " & _
"ON bpm.Code = fds.DoorStyleCode " & _
"INNER JOIN tblFamilyLines fl " & _
"ON fds.FamilyLineCode = fl.FamilyLineCode " & _
"WHERE fl.FamilyLineCode = '" & strFamID & "' " & _
"AND ds.DFFactive = 1 " & _
"ORDER BY bpm.[Description] ASC")
Do While Not m_rsDoor.EOF
cboDoorStyle.AddItem m_rsDoor!Description
m_rsDoor.MoveNext
Loop
Set m_rsDoor = Nothing
End Sub
****Edit: I'm using that query to populate a particular drop-down in the app and it is working on both on the SQL server and in the app.
Some of the examples on here use an If loop instead of a Do While Not, but they both get the same thing done and I don't think that's the issue. I also don't think that's the issue because I copied and pasted that part from another menu option on the app and that option works when I click it. It only throws the error when I choose the option I added.
Thanks, I appreciate any help anyone can offer.
Modify like below code:
Private Sub FillDoor()
Dim m_rsDoor As ADODB.Recordset
Set m_rsDoor = New Recordset
Dim ActiveConnection as String
ActiveConnection = "XXXXXXXXXXX"
Dim strSQL as String
strSQL = "SELECT bpm.[Description] " & _
"FROM tblBrandProductMaster bpm " & _
"INNER JOIN tblDoorStyles ds " & _
"ON ds.DoorStyleCode = bpm.Code " & _
"INNER JOIN tblFamilyDoorStyles fds " & _
"ON bpm.Code = fds.DoorStyleCode " & _
"INNER JOIN tblFamilyLines fl " & _
"ON fds.FamilyLineCode = fl.FamilyLineCode " & _
"WHERE fl.FamilyLineCode = '" & strFamID & "' " & _
"AND ds.DFFactive = 1" & _
"ORDER BY bpm.[Description] ASC"
m_rsDoor.open strSQL, ActiveConnection, adOpenStatic, adLockOptimistic
Do While Not m_rsDoor.EOF
cboDoorStyle.AddItem m_rsDoor!Description
m_rsDoor.MoveNext
Loop
Set m_rsDoor = Nothing
End Sub
This error comes when there are no record in the record set. Please check if your query is correct and giving records.
I'm a new user, so please go gentle on me.
I have created an Outlook rule that runs the below script which writes some of the email message properties to an SQL table.
The connection is working fine, when I run this as a macro on a selected message, it works fine... but when I leave it to run as a rule, it just keeps writing the currently selected email...
I can't figure out where I'm going wrong...
Code is below :
Sub TEST_TO_SQL(Item As MailItem)
Dim sSubject As String
Dim sTo As String
Dim sFrom As String
Dim sMsgeID As String
Dim sRcvd As Date
Set Item = Application.ActiveExplorer.Selection.Item(1)
sSubject = Item.Subject
sTo = Item.ReceivedByName
sFrom = Item.SenderEmailAddress
sMsgID = Item.EntryID
sRcvd = Item.ReceivedTime
Const adOpenStatic = 3
Const adLockOptimistic = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open _
"Provider=SQLOLEDB;" & _
"Data Source=SQLSERVER\SQLEXPRESS;" & _
"Trusted_Connection=Yes;" & _
"InitialCatalog=SQLDB;" & _
"User ID=sa;Password=password;"
objRecordSet.Open _
"INSERT INTO [SQLDB].[dbo].[EMAIL_Log] (LogCompanyID, LogSubject, LogStartDate, LogEndDate, LogShortDesc, LogLongDesc, LogFrom, LogTo, LogMessageID, LogCategory1)" & _
"VALUES ('11'," & "'" & sSubject & "'" & ", " & "'" & Format(sRcvd, "yyyy-mm-dd hh:mm:ss", vbUseSystemDayOfWeek, vbUseSystem) & "'" & ", '', 'short desc', 'Long Desc', " & "'" & sFrom & "'" & ", " & "'" & sTo & "'" & ", " & "'" & sMsgID & "'" & ", '47')", objConnection, adOpenStatic, adLockOptimistic
End Sub
You're always using the currently selected mail item. Remove the line:
Set Item = Application.ActiveExplorer.Selection.Item(1)
Then Item will be the one passed in to the Sub
I have two recordset which want to update one of them by value of the other. I did like this
stSql = "SELECT dbo.tblCableProperty.CatalogCode FROM dbo.tblCable INNER JOIN " & _
" dbo.tblCableProperty ON dbo.tblCable.CablePcode = dbo.tblCableProperty.CablePcode" & _
" WHERE dbo.tblCable.prjsubcode=" & prjsubcode & " AND dbo.tblCable.Active=1 " & " And dbo.tblCable.Gtag='" & Gtag & "' And dbo.tblCable.TagNo=" & tagno & " And dbo.tblCable.NTag=" & NTag & " And dbo.tblCable.EndStr='" & EndStr & "'"
rs.Open stSql, cn, adOpenStatic, adLockOptimistic
catalogCode = rs!catalogCode
rs.Close
stSql = "SELECT *,'' as ShowNum FROM viwShowNum WHERE prjsubcode=" & prjsubcode & " AND Active=1 " & " And Gtag='" & Gtag & "' And TagNo=" & tagno & " And NTag=" & NTag & " And EndStr='" & EndStr & "' ORDER BY 8"
rs.Open stSql, cn, adOpenDynamic, adLockOptimistic
rs.MoveFirst
stSql = "Select * from tblCoreCode where CatalogCode=" & catalogCode
Set rsCoreCode = New ADODB.Recordset
rsCoreCode.CursorLocation = adUseClient
rsCoreCode.Open stSql, cn, adOpenStatic, adLockOptimistic
While Not rs.EOF
criteria = "RealNum='" & rs!CoreNo & "'"
rsCoreCode.Filter = criteria
rs!ShowNum = CStr(rsCoreCode!ShowNum)
rsCoreCode.Filter = adFilterNone
rs.MoveNext
Wend
I get the following error on this part
rs!ShowNum = CStr(rsCoreCode!ShowNum)
multiple-step operation generated errors. check each status value
rsCoreCode!ShowNum is varchar(5). I tried to set the value
rs!ShowNum = "1"
but again I got the same error.
where is the problem?
Thank you
As asked in my comment, if rs.Updatable or rs!ShowNum.DataUpdatable are false, you can use this piece of code from Microsoft to retrieve an updatable RecordSet.
Same issue occurred to me the problem was that i violated an object property , in my case it was size the error came out as
"IntegrationException: Problem (Multiple-step operation generated errors. Check each status value.)"
Imports ADODB
Dim _RecordSet As Recordset
_rs.Fields.Append("Field_Name", DataTypeEnum.adVarChar, 50)
_Recordset("Field_Name").Value = _RecordDetails.Field_NameValue
_RecordDetails.Field_NameValue length was more than 50 chars , so this property was violated , hence the error occurred , so you should probably check if you didn't match one of the properties