Why am I getting a type error in my Dlookup function - ms-access-2013

Hi I have a dlookup in my expression builder in MS Access.
It involved dates, when I run it I get a type error.
Any ideas why that is?
=DLookUp("NewValue","[tblAuditTrail]","[frmName]='frmActionDetails' And ActionID='" & [Reports]![PATS_ACTIONID])

Assuming the field ActionID is string-valued, you are missing a closing single quote surrounding the concatenated value:
=DLookUp
(
"NewValue",
"[tblAuditTrail]",
"[frmName]='frmActionDetails' And ActionID='" & [Reports]![PATS_ACTIONID] & "'"
' You were missing this -----^
)
If, in fact, the ActionID contains a numerical value (as is likely the case for an ID), then no quotes are required, e.g.:
=DLookUp
(
"NewValue",
"[tblAuditTrail]",
"[frmName]='frmActionDetails' And ActionID=" & [Reports]![PATS_ACTIONID]
' Removed single quote from here -----^
)

Related

Buffer gets get reduced when escaping dot with back slash

I have the below query
SELECT
categorymap.id,
categorytype.name,
categorytype.value
FROM
categorymap,
categorytype
WHERE
( categorymap.logfilename = '**hello\.log**' )
AND ( categorymap.categorytypeid = categorytype.id )
Index is available for column logfilename of categorymap table.
I noticed the buffer gets was more when not adding "\" before "." in where clause. Both cases, before and after adding "\", index range scan was used on logfilename column as per explain plan.
Could someone please explain what role does '.' play in here in increasing buffer gets?
TIA
If you are talking about this:
= '**hello\.log**'
(maybe it is just = 'hello\.log'; double asterisks for bold?), then: you didn't escape anything. This query will search the logfilename column for exactly such a string: hello followed by a backslash \ followed by a dot . followed by log.
You'd escape a dot in e.g. regular expression, but there's none here, so ...

Oracle SQL: Using Replace function while Inserting

I have a query like this:
INSERT INTO TAB_AUTOCRCMTREQUESTS
(RequestOrigin, RequestKey, CommentText) VALUES ('Tracker', 'OPM03865_0', '[Orange.Security.OrangePrincipal]
em[u02650791]okok
it's friday!')
As expected it is throwing an error of missing comma, due to this it's friday! which has a single quote.
I want to remove this single quote while inserting using Replace function.
How can this be done?
Reason for error is because of the single Quote. In order to correct it, you shall not remove the single quote instead you need to add one more i.e. you need to make it's friday to it''s friday while inserting.
If you need to replace it for sure, then try the below code :
insert into Blagh values(REPLACE('it''s friday', '''', ''),12);
I would suggest using Oracle q quote.
Example:
INSERT INTO TAB_AUTOCRCMTREQUESTS (RequestOrigin, RequestKey, CommentText)
VALUES ('Tracker', 'OPM03865_0',
q'{[Orange.Security.OrangePrincipal] em[u02650791]okok it's friday!}')
You can read about q quote here.
To shorten this article you will follow this format: q'{your string here}' where "{" represents the starting delimiter, and "}" represents the ending delimiter. Oracle automatically recognizes "paired" delimiters, such as [], {}, (), and <>. If you want to use some other character as your start delimiter and it doesn't have a "natural" partner for termination, you must use the same character for start and end delimiters.
Obviously you can't user [] delimiters because you have this in your queries. I sugest using {} delimiters.
Of course you can use double qoute in it it''s with replace. You can omit last parameter in replace because it isn't mandatory and without it it automatically will remove ' character.
INSERT INTO TAB_AUTOCRCMTREQUESTS (CommentText) VALUES (REPLACE('...it''s friday!', ''''))
Single quotes are escaped by doubling them up
INSERT INTO Blagh VALUES(REPLACE('it''s friday', '''', ''),12);
You can try this, (sorry but I don't know why q'[ ] works)
INSERT INTO TAB_AUTOCRCMTREQUESTS
(RequestOrigin, RequestKey, CommentText) VALUES ('Tracker', 'OPM03865_0', q'[[Orange.Security.OrangePrincipal] em[u02650791]okok it's friday!]')
I just got the q'[] from this link Oracle pl-sql escape character (for a " ' ") - this question could be a possible duplicate

FoxPro convert currency to numeric

I'm using Visual FoxPro and I need to convert currency amount into numeric. The 2 columns in the table are tranamt(numeric,12,2) and tranamt2(character)
Here's my example:
tranamt2=-$710,000.99
I've tried
replace all tranamt with val(tranamt2)
and
replace all tranamt with val(strtran(tranamt2, ",",""))
both results give me zero. I know it has something to do with the negative sign but I can't figure it out. Any help is appreciated.
Try this:
replace all tranamt with VAL(STRTRAN(STRTRAN(tranamt2, "$", ""), ",", ""))
This removes the dollar sign and comma in one shot.
need to convert currency amount into numeric
tranamt(numeric,12,2) and tranamt2(character)
First of all a neither a Character Field Type nor a Numeric Field type (tranamt2) are Not a VFP Currency Field type
You may be using the value of a Character field to represent currency, but that does not make it a currency value - just a String value.
And typically when that is done, you do NOT store the Dollar Sign '$' and Comma ',' as part of the data.
Instead, you store the 'raw' value (in this case: "-710000.99") and merely format how that 'raw' value is displayed when needed.
So in your Character field you have a value of: -$710,000.99
Do you have the Dollar Sign '$' and the Comma ',' as part of the field data?
If so, to convert it to a Numeric, you will first have to eliminate those extraneous characters prior to the the conversion.
If they are not stored as part of your field value, then you can use the VAL() 'as is'.
Example:
cStr = "-710000.99" && The '$' and ',' are NOT stored as part of Character value
nStr = VAL(cStr)
?nStr
However if you have the Dollar Sign and the Comma as part of the field data itself, then you can use STRTRAN() to eliminate them during the conversion.
Example:
cStr = "-$710,000.99" && Note both '$' and ',' are part of data value
* --- Remove both '$' and ',' and convert with VAL() ---
nStr = VAL(STRTRAN(STRTRAN(cStr,",",""),"$",""))
?nStr
Maybe something like:
REPLACE tranamt WITH VAL(STRTRAN(STRTRAN(tranamt2,",",""),"$",""))
EDIT: Another alternative would be to use CHRTRAN() to remove the '$' and ','
Something like:
cRemoveChar = "$," && Characters to be removed from String
REPLACE tranamt WITH VAL(CHRTRAN(tranamt2,cRemoveChar,""))
Good Luck
A little late but I use this function call
function MoneyToDecimal
LPARAMETER tnAmount
LOCAL lnAmount
IF VARTYPE(tnAmount) = "Y"
lnAmount = VAL(STRTRAN(TRANSFORM(tnAmount), "$", ""))
ELSE
lnAmount = tnAmount
ENDIF
return lnAmount
endfunc
And can be tested with these calls:
wait wind MoneyToDecimal($112.50)
wait wind MoneyToDecimal($-112.50)
Use the built-in MTON() function to convert a currency value into a numeric value:
replace all tranamt with mton(tranamt2)

VB6 Getting Error when inputting apostrophe on Filter, using ADODB

I'm trying to filter datagrid from a textbox it works but not if apostrophe or ' was typed on the textbox, I'm using ADODB and VB6
Public Sub pGetCustomer(Optional vSearch As String)
If vSearch = "'" Then
xRSTree.Filter = adFilterNone
xRSTree.Requery
Else
xRSTree.Filter = "description like '%" & vSearch & "%' or customercode like '%" & vSearch & "%'"
End If
Private Sub txtSearch_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
As it says in the ADO documentation (when did people fall into this weird habit of calling ADO "ADODB" anyway???):
Note To include single quotation marks (') in the filter Value, use two single quotation marks to represent one. For example, to filter on O'Malley, the criteria string should be "col1 = 'O''Malley'". To include single quotation marks at both the beginning and the end of the filter value, enclose the string with pound signs (#). For example, to filter on '1', the criteria string should be "col1 = #'1'#".
You must also consider wildcard rules here:
If Operator is LIKE, Value can use wildcards. Only the asterisk (*) and percent sign (%) wild cards are allowed, and they must be the last character in the string. Value cannot be null.
But a little confusingly:
In a LIKE clause, you can use a wildcard at the beginning and end of the pattern (for example, LastName Like '*mit*'), or only at the end of the pattern (for example, LastName Like 'Smit*').
You need to "escape" your qoutes or single qoutes. Simple way would be to replace in vSearch all ' with '' and all " with "".

Can a variable act as a space in VBS?

I'm teaching myself VBS and I decided to write a message encryption program. It uses the left and right functions in a loop to read every individual character.
DO
wscript.sleep 100
if Az=0 then
EXIT DO
end if
CR=right(message,aZ)
DEL=left(CR,1)
aZ=aZ-1
zZ=zZ+1
supra=""
supra="supra"
CALL KEYCOUNT
CD=left(keyword,zZ)
TAC=right(CD,1)
....
From there, it sets every character equal to a different letter based on an encryption keyword and moves onto the next character. My problem is I don't know how to deal with spaces in the message. Is there a way to make a variable have the value of a space? I've tried:
set var=space(1)
set var="&"" ""&"
set var=""
set var=" "
set var=""" """
I'm certain there are things I'm not thinking of
Thanks
Joseph
set statement assigns an object reference to a variable or property, or associates a procedure reference with an event. That isn't our case.
var=space(1) ' var contains one space character
var="&"" ""&" ' var contains &" "&
var="" ' var contains a string of zero length
var=" " ' var contains one space character
var=""" """ ' var contains " "
Or, if you would like, declare a constant for use in place of literal value of space (anywhere in your script) as follows:
Const vbSp=" "
Constants are public by default. Within procedures, constants are always private; their visibility can't be changed. Within a script, the default visibility of a script-level constant can be changed using the Private keyword. There are variations:
Private Const vbSp=" "
Public Const vbSp=" "
The problem is that you use Set (cf. here) when assigning a simple/non-object value to a variable. If you loose it, your experimental statements will 'work' (compile & run without error). Look at the output and you'll see that
var = " "
is the correct and most efficient way to assign a (string containing one) space to a variable.

Resources