I am trying to concatenate a number with a symbol in an MS Access textbox.
The field is a number (ie 44), and a symbol (ie °).
I have tried several different ways:
=[myNumber] & " °"
gives a #Type error
=myNumber & " °"
also results in a #Type error
=[myNumber] & [°]
results in a #Name error
=[myNumber] & " °"
works for me in Access 2010.
You can try to explicitely convert it into a string (and check for NULL, because CStr() doesn't like NULL):
=CStr(Nz([myNumber], "")) & " °"
Related
Owner: IIf(isNull([Company]),[OwnerFirst] & ", " [OwnerLast],[Company])
You may have entered an invalid identifier or typed parenthesis following the Null constant
You need another ampersand operator before [OwnerLast]. Try-
=IIF(IsNull([Company]),[OwnerFirst] & ", " & [OwnerLast],[Company])
I am trying to update an inventory stock as follows:
[InventoryStock] = ([CurrentInventoryStock]-[QuantityOrdered])
Note that QuantityOrdered can be decimal, something like: 5.2 or can be full number, something like 8.
The InventoryStock column is set to Number (double)
The QuantityOrdered column is also set to Number (double)
When QuantityOrdered is a full number, like 5, it works perfectly; but when QuantityOrdered is a decimal number, like 7.5 , then I receive:
Run-time error 3144 (syntax error in update statement)
...highlighting the update code that I wrote in VBA.
If Not IsNull(Me.QuantityOrdered) Then
CurrentDb.Execute " UPDATE Inventory SET InventoryStock = InventoryStock - " & Nz(Me.QuantityOrdered.Value, 0) & ""
End If
As described above, my goal is to deducted the quantity ordered (whether decimal or full number) from the Inventory Stock value.
Can someone help me out?
Regarding your problem:
Using implicit string conversion will use a decimal separator following your country/language settings, for example a (,), which causes your issue.
So you should explicitely use Str() to convert the numeric value to a string to get a dot (.) as separator.
Two more small remarks:
NZ(…) is not necessary because you already check that before (If Not IsNull(Me.QuantityOrdered) Then).
Appending just an empty string (& "") is not necessary too.
If Not IsNull(Me.QuantityOrdered) Then
CurrentDb.Execute "UPDATE Inventory SET InventoryStock = InventoryStock - " & Str(Me.QuantityOrdered.Value)
End If
In my project I am using dsum to query a table to compare years. But I want to render the field as a year for the comparison.
Public Function GetValue(whatyear) As Long
GetValue = DSum("Modification", "Accounting Totals", "Format([EntryDate],'yyyy') = " & whatyear & " AND [ModType] like *2*")
End Function
I keep getting this error:
Syntax error (missing opeator in query expression
'Format([EntryDate],'yyyy' = 2016 AND [ModType] like *2*"
This is probably an easy one for you VBA Gurus. What do I do?
you need qoutes for the year, and if [ModType] is text, you need qoutes for it as well. in addition, handle null values like this, else if it doesn't find any rows, that will throw another error:
Nz(DSum("Modification", "Accounting Totals", "Format([EntryDate],'yyyy') = '" & whatyear & "' AND [ModType] like '*2*' "), 0)
if [ModType] is a numeric value, then the like operator is not going to work, you need to use another operator such as these: =, >=, <=, BETWEEN
Got it - I had to remove the As Long from the function declaration
If so, you may have zero records and DSum returns Null. Catch that - as O. Gungor showed - with Nz. And get the year as a number:
So:
Public Function GetValue(ByVal whatyear As Integer) As Currency
GetValue = Nz(DSum("Modification", "Accounting Totals", "Year([EntryDate]) = " & whatyear & " AND [ModType] Like '*2*'"), 0)
End Function
Sorry, another question about MsAccess.
I have data set:
Phone Number
444-514-9864
555-722-2273
333-553- 4535
000-000- 0000
550-322-6888
444-896-5371
322-533-1448
222.449.2931
222.314.5208
222.745.6001
I need it to look like (222) 896-5371.
How do I do it in Ms Access or MsExcel?
You can use the Instr, mid, Left and Right functions to make this work. I have made 1 example, with msdn you should be able to figure out the rest
Dim OldPhoneNumber As String
Dim NewPhoneNumber As String
Dim PreFix As String
Dim PreFix2 As String
' You can replace this line in Access, just make sure the full phone number is stored in "OldPhoneNumber"
OldPhoneNumber = Worksheets(<worksheet name>).Range(<cell name>).Value
PreFix = Left(OldPhoneNumber, InStr(1, OldPhoneNumber, "-", 1))
PreFix2 = Left(OldPhoneNumber, InStr(1, OldPhoneNumber, "-", 1) - 1)
NewPhoneNumber = Replace(OldPhoneNumber, PreFix, "(" & PreFix2 & ") ")
Debug.Print (NewPhoneNumber)
Seeing as not all your phone numbers are formatted the same way, you would have to make a different rule for every different formatted phone number (you need 1 that checks for "-" and one that checks for "." You also might want to filter out the spaces
In Access you set the "Input mask" to : "("000") "000"-"0000;1;_
All the references http://office.microsoft.com/en-ca/access-help/input-mask-syntax-and-examples-HP005187550.aspx
Input mask will only work for new data. You will need to create a macro or function to update your existing data to be consistent with your desired format
As the question says, I get this error whenever I try to run my query.
I have 3 fields I want to search in each table, an OEM code, models and additional search terms.
Here is the SQL:
PARAMETERS [Search] Text ( 255 );
SELECT *
FROM inkSearch
WHERE inkSearch.[OEMCode] & inkSearch.[printers] & inkSearch.[ast] LIKE "*" & [Search] & "*"
UNION SELECT *
FROM tonerSearch
WHERE tonerSearch.[OEM Code] & tonerSearch.[Models] & tonerSearch.[Additional Search Terms] LIKE "*" & [Search] & "*";
The error goes away if I remove the LASERS.[Models] field, however this is no different to the inks printers field and I can see no reason this is giving me problems.
I have changed the query to this which seems to work. I had initially based it off two queries that narrowed down the fields.
I also discovered that the Models field was text on the toner table and memo on the inks which may have caused it.
The below query appears to have fixed this issue:
PARAMETERS [Search] Text ( 255 );
SELECT LASERS.[OEM], LASERS.[T1inclSell], LASERS.[Yield], LASERS.[Models], LASERS.[AST]
FROM LASERS
WHERE (LASERS.[OEM] & LASERS.[Models] & LASERS.[AST]) Like "*" & [Search] & "*"
UNION ALL SELECT INKS.[OEM], INKS.[T1inclSell], INKS.[Yield], INKS.[Models], INKS.[AST]
FROM INKS
WHERE (INKS.[OEM] & INKS.[Models] & INKS.[AST]) Like "*" & [Search] & "*";