Combine Statements

kitty77

Registered User.
Local time
Today, 17:40
Joined
May 27, 2019
Messages
719
How would I combine these statements? Default for image1 is not visible.

If Me.Mdid = "ABC123" Then Me.image1.Visible = True Else Me.image1.Visible = False
If Me.Mdid = "DEF123" Then Me.image1.Visible = True Else Me.image1.Visible = False
If Me.Mdid = "GHI123" Then Me.image1.Visible = True Else Me.image1.Visible = False
 
This is perfect. Just what I was looking for. Thanks!
 
I always use it this way :

Code:
image1.Visible = InStr(",ABC123,DEF123,GHI123,",  "," & Mdid & ",") > 0
 
Last edited:
English is not my native language and it's really hard to explain what's going on there. I only have learnt it over the years I'm playing with Access.
I hope someone else pop in and explain it.

For now:
Since the code is running in a form's module, I never use Me before controls name. I may be wrong but it makes the code simpler to read.
It means that I use Mdid instead of Me.Mdid.

image1.Visible =
Left part of the equal sign is used to set the property. image1.Visible = means I want to set a value for the visibility of image1.
In the right side I have a function to return a False Or True.

InStr("ABC123,DEF123,GHI123,", Mdid & ",") > 0
InStr function checks the position of the first occurrence of one string within another.
I'm asking Instr to see if the position of Mdid & "," in "ABC123,DEF123,GHI123," is greater than 0 or not.

If instr returns 0, it means that Mdid & "," can not be found in "ABC123,DEF123,GHI123,"
This causes the right side of the equal sign to return a False value.
And image1.Visible = Flase

Otherwise
If instr returns a number greater than 0, it means that Mdid & "," can be found in "ABC123,DEF123,GHI123,"
This causes the right side of the equal sign to return a True value.
And image1.Visible = True


Note : The , before and after Mdid is added just to be certain for an exact check and prevent error if Mdid is empty or null
 
Last edited:

Users who are viewing this thread

Back
Top Bottom