Combine Statement

kitty77

Registered User.
Local time
Today, 03:02
Joined
May 27, 2019
Messages
715
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
 
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.
 
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
 
@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
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
'''''''''''''''''''''''''''''''''''''''''''''''
 
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:
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:
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!!
 
Can eliminate two concatenations. See post 7.
 
you put your single quotes in their own concatenation
Code:
 & "'" &
June put hers in the leading and trailing concatenation
Code:
...'" & SampleID &"' Or...
 
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

 
How do you get Access VBA to recognize CSQL() function?
 
Its a UDF that i put in all my template DBs. Its in the link.
 
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

Back
Top Bottom