weird issue with SQL query in MS Access (Office 365) - ms-access

I have recently inherited a process that requires running queries in MS Access database. Yesterday I stumbled upon the following weird issue, which I can not logically explain:
The query does not run in the latest version of the database file (August 2021 data)
Error message: "undefined VAL() function". When I remove VAL(), a new error message appears: "undefined MID() function"; the messages do not make any sense, as both functions are used in MS SQL.
The same query ran fine in the earlier (May 2021) version of the database, which I downloaded from the corporate server (backup copy, available through "previous versions")
when I copy the query from May database to Aug database, I receive error messages as in "1" (above).
When I copy data from Aug file into May file, the query runs fine. This makes me think that the problem is not a data issue.
I am not sure if the person who produced the reporting before me has done something with August file, or whether this is a weird computer glitch...
I know how to fix the problem (i.e. by copying data from August database to May database), but I am at a loss as to the cause of the error. Any assistance will be highly appreciated!
SQL Query Code (converts USD to CAD):
UPDATE T1_DEF_EXPENSETYPE_COST AS F1, SM_FX_MAVG AS F2 SET F1.CDE = F1.COA * IIF( CURRENCY_TYPE = 'CAD',1,
IIF(MID(F1.PERIOD,10,2) = '01',F2.[M12],0) +
IIF(MID(F1.PERIOD,10,2) = '02',F2.[M01],0) +
IIF(MID(F1.PERIOD,10,2) = '03',F2.[M02],0) +
IIF(MID(F1.PERIOD,10,2) = '04',F2.[M03],0) +
IIF(MID(F1.PERIOD,10,2) = '05',F2.[M04],0) +
IIF(MID(F1.PERIOD,10,2) = '06',F2.[M05],0) +
IIF(MID(F1.PERIOD,10,2) = '07',F2.[M06],0) +
IIF(MID(F1.PERIOD,10,2) = '08',F2.[M07],0) +
IIF(MID(F1.PERIOD,10,2) = '09',F2.[M08],0) +
IIF(MID(F1.PERIOD,10,2) = '10',F2.[M09],0) +
IIF(MID(F1.PERIOD,10,2) = '11',F2.[M10],0) +
IIF(MID(F1.PERIOD,10,2) = '12',F2.[M11],0)), F1.FX_PERIOD = MID(F2.PERIOD,4,4) &
IIF(MID(F1.PERIOD,10,2) = '01','-M12','') &
IIF(MID(F1.PERIOD,10,2) = '02','-M01','') &
IIF(MID(F1.PERIOD,10,2) = '03','-M02','') &
IIF(MID(F1.PERIOD,10,2) = '04','-M03','') &
IIF(MID(F1.PERIOD,10,2) = '05','-M04','') &
IIF(MID(F1.PERIOD,10,2) = '06','-M05','') &
IIF(MID(F1.PERIOD,10,2) = '07','-M06','') &
IIF(MID(F1.PERIOD,10,2) = '08','-M07','') &
IIF(MID(F1.PERIOD,10,2) = '09','-M08','') &
IIF(MID(F1.PERIOD,10,2) = '10','-M09','') &
IIF(MID(F1.PERIOD,10,2) = '11','-M10','') &
IIF(MID(F1.PERIOD,10,2) = '12','-M11',''), F1.FX_Rate = IIF( CURRENCY_TYPE = 'CAD',1,
IIF(MID(F1.PERIOD,10,2) = '01',F2.[M12],0) +
IIF(MID(F1.PERIOD,10,2) = '02',F2.[M01],0) +
IIF(MID(F1.PERIOD,10,2) = '03',F2.[M02],0) +
IIF(MID(F1.PERIOD,10,2) = '04',F2.[M03],0) +
IIF(MID(F1.PERIOD,10,2) = '05',F2.[M04],0) +
IIF(MID(F1.PERIOD,10,2) = '06',F2.[M05],0) +
IIF(MID(F1.PERIOD,10,2) = '07',F2.[M06],0) +
IIF(MID(F1.PERIOD,10,2) = '08',F2.[M07],0) +
IIF(MID(F1.PERIOD,10,2) = '09',F2.[M08],0) +
IIF(MID(F1.PERIOD,10,2) = '10',F2.[M09],0) +
IIF(MID(F1.PERIOD,10,2) = '11',F2.[M10],0) +
IIF(MID(F1.PERIOD,10,2) = '12',F2.[M11],0))
WHERE F1.COA IS NOT NULL AND
VAL(MID(F1.PERIOD,4,4)) = VAL(MID(F2.PERIOD,4,4)) + VAL(IIF(MID(F1.PERIOD,10,2) = '01',1,0)) AND
F2.BASE_RATE = 'CAD' AND F2.CURRENCY_CODE = 'USD';

Related

JavaFX SQL syntax error

I recently got an error in my SQL syntax and I cannot figure out what the problem is.
String table = "rfc";
String update = "UPDATE "+table+" set Type = '" + AWBTypeBox.getValue() + "' set Aantal = " + AWBAantal.getText() + " set Gewicht = " + AWBGewicht.getText() + " set Volume = " + AWBVolume.getText() + " set Beschadiging = '" + AWBBeschadiging.getText() + "' where idReservering = " + account_id + "";
Statement statement = dbCon.conDatabase().createStatement();
int resultSet = statement.executeUpdate(update);
The error it gives is:
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set Aantal = 2 set Gewicht = 20 set Volume = 15 set Beschadiging = 'ja' where id' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
I tried 1 hour trying to change things in the syntax but nothing fixed the error.
The set only occurs once in an update:
UPDATE "+table+"
set Type = '" + AWBTypeBox.getValue() + "',
Aantal = " + AWBAantal.getText() + ",
Gewicht = " + AWBGewicht.getText() + ",
Volume = " + AWBVolume.getText() + ",
Beschadiging = '" + AWBBeschadiging.getText() + "'
where idReservering = " + account_id + "";
You should replace all but the first set with a comma.
The lines are split over multiple rows for clarity. You should format them as necessary for your application.
Note: It is also much safer to use parameters in queries. However, you cannot parameterize a table name, so you still need to put that directly into the string.

Google Form to Create an Event in Calendar

I have created a Google Form for our local scout district, to notify that they will be taking the section out and about. This is all working fine as is the notification email. What I am trying to do is automatically create a calendar event, this will be later shared through out website so that the management team can view and see where all of the scouts are.
Anyway back on track, the fields that I have so far are:
function CalendarSubmit(e){
var Group = e.values[1];
var ActivityDateStart = e.values[2];
var ActivityTimeStart = e.values[3];
var ActivityDateEnd = e.values[4];
var ActivityTimeEnd = e.values[5];
var Activity = e.values[6];
var Location = e.values[7];
var Description = e.values[8];
var AuthLeader = e.values[9];
var AuthLeaderNo = e.values[10];
var AuthLeaderPermit = e.values[11];
var LeaderCharge = e.values[12];
var LeaderChargeNo = e.values[13];
var LeaderEmail = e.values[14]
var Adults = e.values[15];
var Beavers = e.values[16];
var Cubs = e.values[17];
var Scouts = e.values[18];
var Explorers = e.values[19];
var Other = e.values[20];
var InTouchName = e.values[21];
var InTouchContact = e.values[22];
var ManagerEmail = e.values[23];
var RA = e.values[24];
var Rules = e.values[25];
}
I want the calendar title to use the Variable Title, where
var Title = group + " - " + Activity;
Start and Finish Times:
var Start = ActivityDateStart + ActivityTimeStart;
var End = ActivityDateEnd + ActivityTimeEnd;
Location:
var LOC = Location
Description:
var calDescription = "Location of Activity: " + Activity + " /n" +
"Description of Activity: " + Description + " /n/n" +
"Leader in Charge: " + LeaderCharge + " /n" +
"No. of Adults (18+): " + Adults + " /n" +
"No. of Beavers: " + Beavers + " /n" +
"No. of Cubs: " + Cubs + " /n" +
"No. of Scouts: " + Scouts + " /n" +
"No. of Explorers/Young Leaders: " + Explorers + " /n" +
"No. of Non-Uniformed Young People (Under 18): " + Other;
The trouble I am having is that I am not sure how to script all of the above into the CalendarApp.

syntax error during update limt or update top(1) c# & access

I have syntax error in this code
string JSS_connetionString011 = null;
OleDbConnection JSS_connection011;
OleDbDataAdapter JSS_oledbAdapter011 = new OleDbDataAdapter();
string JSS_sql011 = null;
JSS_connetionString011 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/je_salestoredb.mdb;Persist Security Info=True;Jet OLEDB:Database Password=JEPTUSJSSJes";
JSS_connection011 = new OleDbConnection(JSS_connetionString011);
JSS_sql011 = "update product set Siv_Sales_Invoice_NO = '" + textBox1.Text + "' , prod_Status = '" + JSS_product_Status + "' , prod_SALED_ftrCalc = '" + textBox10.Text + "' , piv_SALED_DATE = '" + dateTimePicker1.Text + "' , sivd_ID = '" + textBox3.Text + "' , prod_ROOM ='" + JSS_product_Warhousee + "' where( prod_COMPANY = '" + comboBox4.Text + "' and prod_MODEL = '" + comboBox5.Text + "' and prod_Status = '" + JSS_Ready_For_Sale + "' ORDER BY prod_COMPANY LIMIT 1 )";
JSS_connection011.Open();
JSS_oledbAdapter011.UpdateCommand = JSS_connection011.CreateCommand();
JSS_oledbAdapter011.UpdateCommand.CommandText = JSS_sql011;
JSS_oledbAdapter011.UpdateCommand.ExecuteNonQuery();
Syntax error (missing operator) in query expression '( prod_COMPANY = 'NSN' and prod_MODEL = '606' and prod_Status = 'true' ORDER BY prod_COMPANY LIMIT 1 )'.
There are many records with the same conditions of the query sentence, but each of them have different id.
Any Ideas?
Okay, a couple of things:
One, you can't use ORDER BY or LIMIT in an UPDATE statement in an Access database. The example you linked to is for MySQL, a different database.
Two: What Jon Skeet says is absolutely true: you need to use parameterized SQL rather than putting values directly in SQL.
Three: Given that ORDER BY and LIMIT are not valid in Access update statements, if you replace this bit of code:
+ JSS_Ready_For_Sale + "' ORDER BY prod_COMPANY LIMIT 1 )";
... with this:
+ JSS_Ready_For_Sale + "')";
... the syntax error, or at least that syntax error, may go away.
You might also want to be put a space between the WHERE and the (. I don't know that that will count as a syntax error, but it might.
ETA: ALSO! If you only want to update one record, the one with a specific ID (which I infer from your question text) you will need to specify that record ID in the WHERE clause.
If you records don't have unique IDs, you have a very big problem that you need to fix. A unique ID is absolutely required if you want to be able to update a specific record.
You will also need a properly format string expression for the date:
piv_SALED_DATE = #" + dateTimePicker1.Value.ToString("yyyy'/'MM'/'dd") + "# ,
and in Access SQL you will use "Select Top n .." to select the first n values.

Check for modem

I have some computers with modems and others without using the same database. They db needs to determine if there is a modem installed. I found code created by KHaled El-Menshawy on the Internet which has the potential to do exactly what I want it to do but I get an "Object required" error. I think this is a simple fix, but I don't know how this object should be declared. Can anyone figure out the missing code? Here is his code:
Public Function CheckModem()
On Error GoTo Errr
If ProgBar.Value = 100 Then
ProgBar.Value = 0
End If
Port = 1
PortinG:
MSComm1.CommPort = Port
MSComm1.PortOpen = True
ProgBar.Value = ProgBar.Value + 20
Label1.Caption = ProgBar.Value & "%"
Form1.MSComm1.Settings = "9600,N,8,1"
MSComm1.Output = "AT" + Chr$(13)
X = 1
Do: DoEvents
X = X + 1
If X = 1000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 2000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 3000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 4000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 5000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 6000 Then MSComm1.Output = "AT" + Chr$(13)
If X = 7000 Then
MSComm1.PortOpen = False
Port = Port + 1
GoTo PortinG:
If MSComm1.CommPort >= 6 Then
Errr:
MsgBox "Can't Find Modem"
GoTo done
End If
End If
Loop Until MSComm1.InBufferCount >= 2
instring = MSComm1.Input
MSComm1.PortOpen = False
ProgBar.Value = 100
Label1.Caption = ProgBar.Value & "%"
Text1.Text = "com" & Port 'MSComm1.CommPort & instring
MsgBox "Modem found On Com" & Port
done:
End Function
MsComm1, if you are just copy and pasting from the code looks like it is a MsComm control object. You will have to add it as an additional control to the form, and then you can access its properties.
I suggest avoiding copy and pasting code that you don't understand, try to understand what it is doing and why. Alternatively, this link (from this question) gives a completely different way to do it, avoiding the need to add the control to the form.

Overwriting existing filename in subscription

I have a batch file that deploys a .rss file. The rss file has script that creates a subscription for 10 reports. Once when the batch file is deployed, the .rss file is triggered which in turn cretaes subscription in the "report manager"(For all the 10 reports).
My problem is, each time I deploy the batch file a new set of subscription is created. i.e) instead of overwriting the existing subscription, a new set of duplicates are created. i end up with many subscriptions for a single report.
I need a script that overwrites the existing files on deploying.Do I have to use any method??
Help needed..
code to create subscription:This is pretty messy!bear with me..:)
Sub Main()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
'The name of the report for which the DDS are to be created
Dim fullpath As String = rootpath
'set extension as Windows File Share
Dim settings as new ExtensionSettings()
settings.Extension = "Report Server FileShare"
'Retrieve rdl files deployed in the server
Dim report As String
Dim desc As String
Dim eventType As String = "TimedSubscription"
Dim destpath As String = Path
Dim i as Integer = 0
Dim items As CatalogItem() = rs.ListChildren(fullpath, False)
For Each item As CatalogItem In items
If item.Type = ItemTypeEnum.Report Then
i = i + 1
desc = item.name
report = fullpath &"/" & desc
Dim drp As DataRetrievalPlan
Dim ser As Serialization.XmlSerializer = New Serialization.XmlSerializer(GetType(DataRetrievalPlan))
Dim sr As New StringReader("<?xml version=""1.0"" encoding=""utf-16""?>" + Microsoft.VisualBasic.ControlChars.CrLf + "<DataRetrievalPlan xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" + Microsoft.VisualBasic.ControlChars.CrLf + " <DataSourceDefinition xmlns=""http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices"">" + Microsoft.VisualBasic.ControlChars.CrLf + " <Extension>SQL</Extension>" + Microsoft.VisualBasic.ControlChars.CrLf + " <ConnectString>Data Source="& DBServer & ";Initial Catalog=ClearviewBilling</ConnectString>" + Microsoft.VisualBasic.ControlChars.CrLf + " <UseOriginalConnectString>false</UseOriginalConnectString>" + Microsoft.VisualBasic.ControlChars.CrLf + " <OriginalConnectStringExpressionBased>false</OriginalConnectStringExpressionBased>" + Microsoft.VisualBasic.ControlChars.CrLf + " <CredentialRetrieval>Store</CredentialRetrieval>" + Microsoft.VisualBasic.ControlChars.CrLf + " <WindowsCredentials>false</WindowsCredentials>" + Microsoft.VisualBasic.ControlChars.CrLf + " <ImpersonateUser>false</ImpersonateUser>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Prompt>Enter a user name and password to access the data source:</Prompt>" + Microsoft.VisualBasic.ControlChars.CrLf + " <UserName>RptSrvr</UserName>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Password>deploy1</Password>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Enabled>true</Enabled>" + Microsoft.VisualBasic.ControlChars.CrLf + " </DataSourceDefinition>" + Microsoft.VisualBasic.ControlChars.CrLf + " <DataSet xmlns=""http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices"">" + Microsoft.VisualBasic.ControlChars.CrLf + " <Fields>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Field>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Alias>ReportID</Alias>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Name>ReportID</Name>" + Microsoft.VisualBasic.ControlChars.CrLf + " </Field>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Field>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Alias>ReportName</Alias>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Name>ReportName</Name>" + Microsoft.VisualBasic.ControlChars.CrLf + " </Field>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Field>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Alias>Path</Alias>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Name>Path</Name>" + Microsoft.VisualBasic.ControlChars.CrLf + " </Field>" + Microsoft.VisualBasic.ControlChars.CrLf + " </Fields>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Query>" + Microsoft.VisualBasic.ControlChars.CrLf + " <CommandType>Text</CommandType>" + Microsoft.VisualBasic.ControlChars.CrLf + " <CommandText>exec uspSetSubscriptionParameters "& i & ",'"& destpath &"'</CommandText>" + Microsoft.VisualBasic.ControlChars.CrLf + " <Timeout>30</Timeout>" + Microsoft.VisualBasic.ControlChars.CrLf + " </Query>" + Microsoft.VisualBasic.ControlChars.CrLf + " <CaseSensitivity>False</CaseSensitivity>" + Microsoft.VisualBasic.ControlChars.CrLf + " <AccentSensitivity>False</AccentSensitivity>" + Microsoft.VisualBasic.ControlChars.CrLf + " <KanatypeSensitivity>False</KanatypeSensitivity>" + Microsoft.VisualBasic.ControlChars.CrLf + " <WidthSensitivity>False</WidthSensitivity>" + Microsoft.VisualBasic.ControlChars.CrLf + " </DataSet>" + Microsoft.VisualBasic.ControlChars.CrLf + "</DataRetrievalPlan>")
drp = ser.Deserialize(sr)
Dim parameters(0) As ParameterValueOrFieldReference
Dim parameter1 As New ParameterFieldReference()
parameter1.ParameterName = "ReportID"
parameter1.FieldAlias = "ReportID"
parameters(0) = parameter1
Dim extensionParams(6) As ParameterValueOrFieldReference
extensionParams(0) = New ParameterFieldReference()
CType(extensionParams(0),ParameterFieldReference).FieldAlias = "ReportName"
CType(extensionParams(0),ParameterFieldReference).ParameterName = "FILENAME"
extensionParams(1) = New ParameterFieldReference()
CType(extensionParams(1),ParameterFieldReference).FieldAlias = "Path"
CType(extensionParams(1),ParameterFieldReference).ParameterName = "PATH"
extensionParams(2) = New ParameterValue()
CType(extensionParams(2),ParameterValue).Name = "RENDER_FORMAT"
CType(extensionParams(2),ParameterValue).Label = ""
CType(extensionParams(2),ParameterValue).Value = "PDF"
extensionParams(3) = New ParameterValue()
CType(extensionParams(3),ParameterValue).Name = "WRITEMODE"
CType(extensionParams(3),ParameterValue).Label = ""
CType(extensionParams(3),ParameterValue).Value = "OverWrite"
extensionParams(4) = New ParameterValue()
CType(extensionParams(4),ParameterValue).Name = "FILEEXTN"
CType(extensionParams(4),ParameterValue).Label = ""
CType(extensionParams(4),ParameterValue).Value = "True"
extensionParams(5) = New ParameterValue()
CType(extensionParams(5),ParameterValue).Name = "USERNAME"
CType(extensionParams(5),ParameterValue).Label = ""
CType(extensionParams(5),ParameterValue).Value = "SQL_Test"
extensionParams(6) = New ParameterValue()
CType(extensionParams(6),ParameterValue).Name = "PASSWORD"
CType(extensionParams(6),ParameterValue).Label = ""
CType(extensionParams(6),ParameterValue).Value = "Rfgh"
Dim extSettings As New ExtensionSettings()
extSettings.ParameterValues = extensionParams
extSettings.Extension = "Report Server FileShare"
Dim matchData As String = "<ScheduleDefinition xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><StartDateTime xmlns=""http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices"">2011-02-14T01:00:00.000-05:00</StartDateTime></ScheduleDefinition>"
Try
rs.CreateDataDrivenSubscription(report, extSettings, drp, desc, eventType, matchData, parameters)
Console.WriteLine("Subscription created successfully for "&desc)
catch ex as System.Exception
Console.WriteLine(ex)
end try
End If
Next
End Sub
Probably it's just a piping error, using >> instead of >. A code example would be nice.