VBA Coding question (1 Viewer)

Verlooy Jan

New member
Local time
Tomorrow, 00:03
Joined
Nov 2, 2012
Messages
1
I have a small question

How to test in VBA if a field contains a specific text at the end?
In Excel i would use : =Right(field;5)
How to evaluate in aVBA IF statement those 5 last chars ?
I tried several options but got errors all the time.
In general how to use a Excel function in VBA code?:mad:

Thanks on beforehand
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:03
Joined
Sep 21, 2011
Messages
14,231
Use a comma , instead of a semicolon.
Other than that it is the same
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:03
Joined
Feb 19, 2013
Messages
16,607
what have you tried? the VBA for right(field;5) is the same in access vba

the equivalent of the excel IF function is IIF
 

vba_php

Forum Troll
Local time
Today, 17:03
Joined
Oct 6, 2019
Messages
2,880
Use a comma , instead of a semicolon.
Other than that it is the same
not quite. further code is needed than just "=Right(field,5)"


In general how to use a Excel function in VBA code?
generally you would write:
Code:
if right([B]yourTextStringHere[/B], 5) = [B]SpecificTextYourLookingFor[/B] then
     msgbox "String Found" '(or whatever action you want)
else
     msgbox "String Not Found" '(or whatever action you want)
end if
and Jan, try reposting your question in this forum:


https://www.access-programmers.co.uk/forums/forumdisplay.php?f=12


this is the wrong place to ask questions.
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:03
Joined
Sep 21, 2011
Messages
14,231
I have a small question

How to test in VBA if a field contains a specific text at the end?
In Excel i would use : =Right(field;5)
How to evaluate in aVBA IF statement those 5 last chars ?
I tried several options but got errors all the time.
In general how to use a Excel function in VBA code?:mad:

Thanks on beforehand

In fact that is also incorrect, you have to use the comma, the same as Access.:confused:
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:03
Joined
Feb 19, 2013
Messages
16,607
you have to use the comma

in certain parts of the world you use semi colons instead of comma's - and the decimal notation can be different (dots for thousand separators, commas for dp), given the OP's name, I suspect they are from one of those parts.
 

isladogs

MVP / VIP
Local time
Today, 23:03
Joined
Jan 14, 2017
Messages
18,209
Welcome to AWF.
I moved the thread to Modules and VBA as its a coding question

Just wondering whether a semicolon is required for the user's location
e.g. in Italy a comma is used instead of a decimal point and a decimal point instead of a comma. e.g.12.456,50 instead of 12,456.50

In which case a semicolon replaces the the comma as a separator in functions
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:03
Joined
Sep 21, 2011
Messages
14,231
in certain parts of the world you use semi colons instead of comma's - and the decimal notation can be different (dots for thousand separators, commas for dp), given the OP's name, I suspect they are from one of those parts.

Ah yes CJ, sorry, I forgot about that. :eek:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:03
Joined
Oct 29, 2018
Messages
21,453
In general how to use a Excel function in VBA code?:mad:
You would only have to do that if the Excel function doesn't exist in Access. In your case though, Access also has an equivalent Right() function.
 

Users who are viewing this thread

Top Bottom