I am getting error in MS access 2003, Run Time Error 2465: Microsoft can't find the field '|' referred to in your expression.
Count = DCount("*", "PREPAYMENT_PRICING_CHANGE", ([INSERT_DATE] - Int([INSERT_DATE])) = ([Now()] - Int([Now()])))
db.Execute "INSERT INTO tbl_audit ([FilePath],[FileName],[action],[trans_date],[button],[number_of_records])" _
& " values ( '" & strFName & "', '" & File & "' , ""'Import_of_NTS_rate_PCD_file'"" ,Now() ,""'Import NTS rates from file'"",'" & Count & "');"
I think that you forgot the " in the DCount condition:
Count = DCount("*", "PREPAYMENT_PRICING_CHANGE", "([INSERT_DATE] - Int([INSERT_DATE])) = ([Now()] - Int([Now()]))")
Also try to escape your variables:
db.Execute "INSERT INTO tbl_audit ([FilePath],[FileName],[action],[trans_date],[button],[number_of_records])" _
& " values ( '" & Replace(strFName,"'","''") & "', '" & Replace(File,"'","''") & "' , ""'Import_of_NTS_rate_PCD_file'"" ,Now() ,""'Import NTS rates from file'"",'" & Count & "');"
Related
Please assist with adding the value of Text34 from the user into thisParcel expression on MS ACCESS. I get a 3075 run time error when I run the code. I have rechecked my indentation, missing operators, but I cannot find the problem.
Private Sub Command10_Click()
DoCmd.SetWarnings (WarningsOff)
i = Val(Text2.Value)
w = Val(Text34.Value)
If Text8 = "" Or IsNull(Text8) Then
TrueOrFalse = 0
Else
TrueOrFalse = -1
End If
If IsNull(Len(List0.Value)) Then
MsgBox "Choose allotment area"
Exit Sub
End If
thisParcel = List0.Value & Left("00000000", 8 - Len(Trim(Str(i)))) & Trim(Str(i)) +
Left("00000", 5 - Len(Trim(Str(w)))) & Trim(Str(w))
DoCmd.RunSQL "INSERT INTO Schedule ( DiagramNo, OnGP, GPNo, ParcelCode, DiagramDeedNo ) VALUES ( '" & Text6.Value & "', " & TrueOrFalse & " , '" & Text8.Value & "' , '" & thisParcel & " , '" & Text22 & "');"
You have some typos, miss a line continuation, and the code can be reduced a little:
If IsNull(List0.Value) Then
MsgBox "Choose allotment area"
Exit Sub
End If
TrueOrFalse = (Nz(Me!Text8.Value, "") <> "")
thisParcel = List0.Value & _
Left("00000000", 8 - Len(CStr(i))) & CStr(i) & _
Left("00000", 5 - Len(CStr(w))) & CStr(w)
DoCmd.RunSQL "INSERT INTO Schedule ( DiagramNo, OnGP, GPNo, ParcelCode, DiagramDeedNo ) VALUES ( '" & Text6.Value & "', " & TrueOrFalse & ", '" & Text8.Value & "', '" & thisParcel & "', '" & Text22 & "');"
Also, consider my function CSql.
I am trying to create a Form that is used to manually enter data in certain scenarios. Most data is input from CSV files which is working fine. I have 4 tables, Part , Assembly , MachineOrder , and Job. I was able to write code for entering into the base table, Part, from the Form no problem. The issue now is entering data into the Assembly and MachineOrder tables where the Parts are being referenced by their PID autonumber field and the Assemblies are being referenced by their AID autonumbered field. I have tried many different kinds of methods to perform this of which you can see a bit of in my commented out code. What is there is what I believe to be my closest to correct code thus far with the error now being that Access asks me for the parameter value of rPID even though it is finding the value in the Dlookup function fine. I'm assuming the same is true for the rAID section as well.
Otherwise I'm getting errors of Key Violations when using the INSERT then UPDATE method you see commented out.
The form is called HOTEntry
Any advice on what my problem may be is greatly appreciated, I'm a student and this is my first time trying to use what I've learned in a professional application so any and all constructive criticism is wanted! Apologies if this is a rather specific question but I could really use the help on this since I've been working on it for two days to no avail...
My code:
Sub HOTParts2()
Dim rPID As Integer
Dim rAID As Integer
Dim dbs As DAO.Database
Dim sqlstr1 As String
Dim sqlstr2 As String
Dim sqlstr3 As String
Dim sqlstr4 As String
Set dbs = CurrentDb
'sqlstr1 = "INSERT INTO Assembly ( PID, ModelNum, ModelRev, ModelDescription ) " _
' & "SELECT (PID,Forms!HOTEntry!txtHotModel, Forms!HOTEntry!txtHotRev, Forms!HOTEntry!txtHotDes)" _
' & "FROM Part " _
' & "WHERE Part.PartName = Forms!HOTEntry!txtPartName AND Part.Config = Forms!HOTEntry!txtConfigEntry AND Part.Rev = Forms!HOTEntry!txtRevEntry"
sqlstr1 = "INSERT INTO Assembly ( ModelNum, ModelRev, ModelDescription,PID ) " _
& "VALUES (Forms!HOTEntry!txtHotModel, Forms!HOTEntry!txtHotRev, Forms!HOTEntry!txtHotDes," & "rPID" & ");"
'
'sqlstr2 = "UPDATE Assembly " _
' & "SET PID =" & rPID & " " _
' & "WHERE Assembly.ModelNum = Forms!HOTEntry!txtHotModel And Assembly.ModelDescription = Forms!HOTEntry!txtHotDes And Assembly.ModelRev = Forms!HOTEntry!txtHotRev;"
'
'sqlstr3 = "INSERT INTO MachineOrder ( AID, Serial, CustName ) " _
' & "SELECT (AID,Forms!HOTEntry!txtHotSerial, Forms!HOTEntry!txtHotCust)" _
' & "FROM Assembly" _
' & "WHERE Assembly.Model=Forms!HOTEntry!txtHotModel And ModelDescription= Forms!HOTEntry!txtHotDes And ModelRev = Forms!HOTEntry!txtHotRev; "
sqlstr3 = "INSERT INTO MachineOrder (Serial, CustName, AID ) " _
& "VALUES (Forms!HOTEntry!txtHotSerial, Forms!HOTEntry!txtHotCust," & "rAID" & ");"
'
'sqlstr4 = "UPDATE MachineOrder " _
' & "SET AID =" & rAID & " " _
' & "WHERE AID IS NULL;"
rPID = DLookup("PID", "Part", "PartName = " & "'" & Forms!HOTEntry!txtPartName & "'" & " And " & "Config = " & "'" & Forms!HOTEntry!txtConfigEntry & "'" & " And " & "Rev = " & "'" & Forms!HOTEntry!txtRevEntry & "'")
DoCmd.RunSQL sqlstr1
'DoCmd.RunSQL sqlstr2
rAID = DLookup("AID", "Assembly", "ModelNum = " & "'" & Forms!HOTEntry!txtHotModel & "'" & " And " & "ModelDescription = " & "'" & Forms!HOTEntry!txtHotDes & "'" & " And " & "ModelRev = " & "'" & Forms!HOTEntry!txtHotRev & "'")
DoCmd.RunSQL sqlstr3
'DoCmd.RunSQL sqlstr4
End Sub
Well, if you want to use the looked up rPID and rAID in a query, you need to do more than just set them in VBA. You can either manually fill them in in your SQL statement, use a parameter and a QueryDef and fill in the parameter in your QueryDef, or put the DLookUp inside your SQL statement.
Going with the first approach here, only unquoted rPID in your initial statement, and put it after rPID was set.:
rPID = DLookup("PID", "Part", "PartName = " & "'" & Forms!HOTEntry!txtPartName & "'" & " And " & "Config = " & "'" & Forms!HOTEntry!txtConfigEntry & "'" & " And " & "Rev = " & "'" & Forms!HOTEntry!txtRevEntry & "'")
sqlstr1 = "INSERT INTO Assembly ( ModelNum, ModelRev, ModelDescription,PID ) " _
& "VALUES (Forms!HOTEntry!txtHotModel, Forms!HOTEntry!txtHotRev, Forms!HOTEntry!txtHotDes," & rPID & ");"
DoCmd.RunSQL sqlstr1
I have 3 combobox to filter data, then i want to open in command button to print preview..
Problems I have if i used 2 combobox it works but when i used three combobox the report is blank...there's any problems with the code?? here's the code i used :
Dim strWhereCondition As String
strWhereCondition = "[month] = '" & Me.cbmonth.Value _
& "' and [Works] = '" & Me.cbwork.Value _
& "' and [Works] = '" & Me.cbwork2.Value & "'"
Debug.Print strWhereCondition
DoCmd.OpenReport "Month List", View:=acViewPreview, _
WhereCondition:=strWhereCondition
and the requery for my form
SELECT *
FROM MyTable
WHERE (month = Forms!nameForm!cbmonth
OR Forms!MeForm!cbwork IS NULL)
And (works = Forms!nameForm!cbwork
OR Forms!nameForm!cbwork IS NULL)
AND (works = Forms!nameForm!cbwork2
OR Forms!nameForm!cbwork2 IS NULL);
can anyone help?
Month is a number, so try:
strWhereCondition = "[month] = " & Me.cbmonth.Value _
& " and [Works] = '" & Me.cbwork.Value _
& "' and [Works] = '" & Me.cbwork2.Value & "'"
Edit: Month is text.
However, [Work] is supposed to match two potentially different values:
& "' and [Works] = '" & Me.cbwork.Value _
& "' and [Works] = '" & Me.cbwork2.Value & "'"
Should most likely be:
& "' and [Works] = '" & Me.cbwork.Value _
& "' and [SomeOtherField] = '" & Me.cbwork2.Value & "'"
My code for saving is unstable sometimes it saves and sometimes it gives this error:
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 's' , '50931213' , '50' , '7.20' , '7.42' , '7.78' , '08-13-2016' , '07-19-2018' ' at line 1
Could you guys help me debug?
Here's my code:
Dim cmd3 As MySqlCommand = New MySqlCommand(query, con)
con.Open()
query = "INSERT INTO tblproduct(ProductNo, GenericName, BrandName, CompanyNo, Quantity, BuyingPrice, WholesalePrice, RetailPrice, PurchasedDate, ExpirationDate, Status)VALUES('" _
& txt_prodno.Text & "' , '" _
& cmb_gname.Text & "' , '" _
& txt_bname.Text & "' , '" _
& txt_comno.Text & "' , '" _
& txt_quantity.Text & "' , '" _
& txt_bprice.Text & "' , '" _
& txt_wprice.Text & "' , '" _
& txt_rprice.Text & "' , '" _
& txt_pdate.Text & "' , '" _
& txt_edate.Text & "' , '" _
& cmb_status.Text & "')"
cmd3 = New MySqlCommand(query, con)
Dim i As Integer = cmd3.ExecuteNonQuery()
MsgBox("Product Saved!", vbInformation)
loadrec()
con.Close()
Ok. The debugger pointed at:
i As Integer = cmd3.ExecuteNonQuery()
and started at txt_comno which is CompanyNo down to txt_edate which is ExpirationDate.
I suspected that I messed up with my data fields matching and quotes but everything is in place. As I have said earlier I can save records. How ever there are times that this error would occur making it an unstable saving function..
I have some VBA code that sets a TempVar:
TempVars!ThisQtr = quarter
TempVars!LastQtr = lastQuarter
TempVars!LastYr = lastYear
TempVars!ThisYr = currentYear
Great! I know that it does set it as I have checked multiple times.
now my problem:
I'm trying to use this in a query
DSum("[SumBase]","CompareUnionQuery","[AU] = '" & [AU] & "' AND [GRP_ID] = " & [GRP_ID] & " AND [ACCOUNT] = '" & [ACCOUNT] & "'" & " AND [Fiscal_Year] = " & [TempVars]![ThisYr] & " AND [QTR]= " & [TempVars]![ThisQtr])
which this does work when I change out the TempVars with values. Can anyone help me with this?
I have tried to put a single quote around them and that doesn't work.
this expression does work:
DSum("[SumBase]","CompareUnionQuery","[AU] = '" & [AU] & "' AND [GRP_ID] = " & [GRP_ID] & " AND [ACCOUNT] = '" & [ACCOUNT] & "'" & " AND [Fiscal_Year] = 2015 AND [QTR]= '3'")
Compare the last pieces of your DSum expressions ...
AND [QTR]= '3'")
AND [QTR]= " & [TempVars]![ThisQtr])
You reported #1 works and #2 triggers the "Data type mismatch" error. So add single quotes before and after the TempVar value ...
AND [QTR]= '" & [TempVars]![ThisQtr] & "'")