Combine Statement (1 Viewer)

kitty77

Registered User.
Local time
Today, 02:01
Joined
May 27, 2019
Messages
712
How can I combine these into one statement? Msampleid1 or Msampleid2

DoCmd.OpenForm "TextSend", acNormal, "", "[Msampleid1]=" & "'" & SampleID & "'", , acNormal
DoCmd.OpenForm "TextSend", acNormal, "", "[Msampleid2]=" & "'" & SampleID & "'", , acNormal
 

GPGeorge

Grover Park George
Local time
Yesterday, 23:01
Joined
Nov 25, 2004
Messages
1,864
Try:

DoCmd.OpenForm "TextSend", acNormal, "", "[Msampleid1]=" & "'" & SampleID & "' OR [Msampleid2]=" & "'" & SampleID & "'", , acNormal

Since my ability to inspect double and single quotes is marginal, you may need to tweak that to get it correct.
 

SHANEMAC51

Active member
Local time
Today, 09:01
Joined
Jan 28, 2022
Messages
310
Since my ability to inspect double and single quotes is marginal, you may need to tweak that to get it correct.
Code:
Dim S1
'text
S1 = "[MSAMPLEID1]='s%1' OR [MSAMPLEID2]='s%1'"
S1 = Replace(S1, "s%1", SAMPLEID)
'long
S1 = "[MSAMPLEID1]=s%1 OR [MSAMPLEID2]=s%1"
S1 = Replace(S1, "s%1", SAMPLEID)
debug.print s1
DoCmd.OpenForm "TEXTSEND", acNormal, , S1, acFormEdit, acWindowNormal
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:01
Joined
Feb 19, 2002
Messages
43,266
@SHANEMAC51
Welcome aboard

I think you might be over complicating the problem. George's one line solution solves the problem. Unless you are getting paid by the lines of code you write, most of the time, one line will be better than eight.
 

SHANEMAC51

Active member
Local time
Today, 09:01
Joined
Jan 28, 2022
Messages
310
@SHANEMAC51
Welcome aboard

I think you might be over complicating the problem. George's one line solution solves the problem. Unless you are getting paid by the lines of code you write, most of the time, one line will be better than eight.
I don't get paid for lines, but I take care of my eyes and nerves
in the code editor, I try on a font of 14 points, it's about 100 characters

I really don't like it when a line of code is longer than 100 characters and doesn't fit into the screen
, so I break ALL long lines into substrings, and without a hyphen (preferably)

instead of a string 500-1000 characters received in the designer/editor requests
sw="select ...... from....... inner join ...... on ...... where ....... and ......."

I get several lines less than 100 characters long, and I don't use line margins often and no more than 1-2 positions
, I separate the code blocks with a line from """'
IT'S MUCH MORE READABLE
Code:
''''''''''''''''''''''''''''''' комментарий ''''''''''''''''''
Dim SW As String
SW = "select ...... "
SW = SW & " from....... "
SW = SW & " inner join ...... "
SW = SW & " on ...... "
SW = SW & " where ....... "
SW = SW & " and ......."
CurrentDb.Execute SW
'''''''''''''''''''''''''''''''''''''''''''''''
 

SHANEMAC51

Active member
Local time
Today, 09:01
Joined
Jan 28, 2022
Messages
310
How can I combine these into one statement? Msampleid1 or Msampleid2

DoCmd.OpenForm "TextSend", acNormal, "", "[Msampleid1]=" & "'" & SampleID & "'", , acNormal
DoCmd.OpenForm "TextSend", acNormal, "", "[Msampleid2]=" & "'" & SampleID & "'", , acNormal
Code:
""""""""' compare the readability of quotation marks """"""""""""""""

""""""" single line option """""""
DoCmd.Open form "TEXTSEND", normal, "", "[Msampleid1]=" & "'" AND Sample ID & "' OR [Msampleid2]=" & "'" AND Sample ID & "'", , Normal

""""""" option broken down into substrings """""""
Dim s1
'text '''''''''''''''''''''''''''''''''''''''''
S1 = "[M SAMPLE ID 1]='s%1' OR [MSAMPLEID2]='s%1'"
S1 = Replace(S1, "s%1", SAMPLEID)
debug.print s1
DoCmd.Open form "SENDING TEXT", acnormal, , S1, acformedit, acWindowNormal
''''''''''''''''''''''''''''
 
Last edited:

June7

AWF VIP
Local time
Yesterday, 22:01
Joined
Mar 9, 2014
Messages
5,470
Using multiple lines to incrementally build long string has its advantage but can be overdone.
Sometimes line continuation is good enough (BTW, continuation character is an underscore, not hyphen):
Code:
DoCmd.OpenForm "TextSend", acNormal, "", "[Msampleid1]='" & SampleID & _
                "' OR [Msampleid2]='" & SampleID & "'", , acNormal
 
Last edited:

kitty77

Registered User.
Local time
Today, 02:01
Joined
May 27, 2019
Messages
712
Try:

DoCmd.OpenForm "TextSend", acNormal, "", "[Msampleid1]=" & "'" & SampleID & "' OR [Msampleid2]=" & "'" & SampleID & "'", , acNormal

Since my ability to inspect double and single quotes is marginal, you may need to tweak that to get it correct.
Perfect!!
 

June7

AWF VIP
Local time
Yesterday, 22:01
Joined
Mar 9, 2014
Messages
5,470
Can eliminate two concatenations. See post 7.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:01
Joined
May 21, 2018
Messages
8,527
you put your single quotes in their own concatenation
Code:
 & "'" &
June put hers in the leading and trailing concatenation
Code:
...'" & SampleID &"' Or...
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:01
Joined
May 21, 2018
Messages
8,527
If I Have a lot of delimiting to do I use the CSQL function to delimit strings, dates, nulls, booleans, numerics
Code:
DoCmd.OpenForm "TextSend", acNormal, "", "[Msampleid1]=" & csql(SampleID) & " OR [Msampleid2]=" & csql(SampleID), , acNormal
Or even add a variable
Code:
dim id as String
id = CSQL(me.sampleid)
DoCmd.OpenForm "TextSend", acNormal, "", "[Msampleid1]=" & ID & " OR [Msampleid2]=" & ID, , acNormal

 

June7

AWF VIP
Local time
Yesterday, 22:01
Joined
Mar 9, 2014
Messages
5,470
How do you get Access VBA to recognize CSQL() function?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:01
Joined
May 21, 2018
Messages
8,527
Its a UDF that i put in all my template DBs. Its in the link.
 

GPGeorge

Grover Park George
Local time
Yesterday, 23:01
Joined
Nov 25, 2004
Messages
1,864
Code:
""""""""' compare the readability of quotation marks """"""""""""""""

""""""" single line option """""""
DoCmd.Open form "TEXTSEND", normal, "", "[Msampleid1]=" & "'" AND Sample ID & "' OR [Msampleid2]=" & "'" AND Sample ID & "'", , Normal

""""""" option broken down into substrings """""""
Dim s1
'text '''''''''''''''''''''''''''''''''''''''''
S1 = "[M SAMPLE ID 1]='s%1' OR [MSAMPLEID2]='s%1'"
S1 = Replace(S1, "s%1", SAMPLEID)
debug.print s1
DoCmd.Open form "SENDING TEXT", acnormal, , S1, acformedit, acWindowNormal
''''''''''''''''''''''''''''
Readable?
 

Users who are viewing this thread

Top Bottom