473,387 Members | 1,291 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

concatenation help needed

Thanks in advance!! I've looked at fConcatFld but that doesn't seem to
be what i'm looking for or I just can't figure it out.

I'm trying to have a button select records based on two combo boxes -
one holding a number and one text.
Floor(combo18) is a floor number and site(combo20) is a building
name

Private Sub Command22_Click()
Dim strSQL As String
strSQL = "Select * FROM [qryAllSlrSites]"

strSQL = strSQL & "WHERE ((([qryAllSlrSites].[Exclude])=False) AND
((qryAllSlrSites.Floor)=" & Me.Combo18 & "))"

strSQL = strSQL & " AND ((qryAllSlrSites.site)= '" & Me.Combo20 & "))"

Me.RecordSource = strSQL
End Sub

Is there a good way to make do this? I've been cutting and pasting
SQL statements trying to put fields in where criteria were in the
statement.

-warning e-mail address altered- arthureNOSPACE@
Nov 13 '05 #1
3 1271
arthur-e wrote:
Thanks in advance!! I've looked at fConcatFld but that doesn't seem to
be what i'm looking for or I just can't figure it out.

I'm trying to have a button select records based on two combo boxes -
one holding a number and one text.
Floor(combo18) is a floor number and site(combo20) is a building
name

Private Sub Command22_Click()
Dim strSQL As String
strSQL = "Select * FROM [qryAllSlrSites]"

strSQL = strSQL & "WHERE ((([qryAllSlrSites].[Exclude])=False) AND
((qryAllSlrSites.Floor)=" & Me.Combo18 & "))"

strSQL = strSQL & " AND ((qryAllSlrSites.site)= '" & Me.Combo20 & "))"

Me.RecordSource = strSQL
End Sub

Is there a good way to make do this? I've been cutting and pasting
SQL statements trying to put fields in where criteria were in the
statement.

-warning e-mail address altered- arthureNOSPACE@
Hmmmm...I might put in the after update event some code like
SetFilter
for each combo box.

THen create a routine

PRivate Sub SetFilter()
Dim strFilter As STring
If Not IsNull(Me.Combo18) Then
strFilter = "Exclude = False And "
"Floor = " & Me.Combo18 & " And "
ENdif

If Not IsNull(Me.Combo20) Then
strFilter = strFilter & _
"Site = " & Me.Combo20 & " And "
ENdif

If strFilter > "" Then
'remove the word And
strFilter = Left(strFilter,Len(strFilter) -5)
Me.Filter = strFilter
Me.FilterOn = True
Else
'no filter
Me.Filter = ""
Me.FilterOn = False
ENdif
ENd SUb


strSQL = strSQL & " AND ((qryAllSlrSites.site)= '" & Me.Combo20 & "))"

Nov 13 '05 #2
THANKIS -
interesting concept - I'll give it a try.
The key in your routine seems to be eliminating the last AND if there
isn't one.

I couldn't even got two simple boxes to work together - I couldn't
keep the """""" and ))))) straight.
Arthur

Salad <oi*@vinegar.com> wrote:
arthur-e wrote:
Thanks in advance!! I've looked at fConcatFld but that doesn't seem to
be what i'm looking for or I just can't figure it out.

I'm trying to have a button select records based on two combo boxes -
one holding a number and one text.
Floor(combo18) is a floor number and site(combo20) is a building
name

Private Sub Command22_Click()
Dim strSQL As String
strSQL = "Select * FROM [qryAllSlrSites]"

strSQL = strSQL & "WHERE ((([qryAllSlrSites].[Exclude])=False) AND
((qryAllSlrSites.Floor)=" & Me.Combo18 & "))"

strSQL = strSQL & " AND ((qryAllSlrSites.site)= '" & Me.Combo20 & "))"

Me.RecordSource = strSQL
End Sub

Is there a good way to make do this? I've been cutting and pasting
SQL statements trying to put fields in where criteria were in the
statement.

-warning e-mail address altered- arthureNOSPACE@


Hmmmm...I might put in the after update event some code like
SetFilter
for each combo box.

THen create a routine

PRivate Sub SetFilter()
Dim strFilter As STring
If Not IsNull(Me.Combo18) Then
strFilter = "Exclude = False And "
"Floor = " & Me.Combo18 & " And "
ENdif

If Not IsNull(Me.Combo20) Then
strFilter = strFilter & _
"Site = " & Me.Combo20 & " And "
ENdif

If strFilter > "" Then
'remove the word And
strFilter = Left(strFilter,Len(strFilter) -5)
Me.Filter = strFilter
Me.FilterOn = True
Else
'no filter
Me.Filter = ""
Me.FilterOn = False
ENdif
ENd SUb


strSQL = strSQL & " AND ((qryAllSlrSites.site)= '" & Me.Combo20 & "))"

-warning e-mail address altered- arthureNOSPACE@
Nov 13 '05 #3
arthur-e wrote:
THANKIS -
interesting concept - I'll give it a try.
The key in your routine seems to be eliminating the last AND if there
isn't one.
It's a common practice that if you are stringing a bunch of conditions
that are ANDed, to add it to the end of each and then remove at the end.
Makes it easy to debug.

Another key is that if you call the routine from each combo, the list
will shrink or expand. For example, in the AfterUpdate event of the
Major combo (Combo18), you could have the code.
Me.Combo20 = Null
SetFilter
Now you get all of the records for the Floor to be displayed.

Then the minor combo (combo20) enter
SetFilter
in the afterupdate event.


I couldn't even got two simple boxes to work together - I couldn't
keep the """""" and ))))) straight.
Arthur
I know what you mean. :-)

If I copy/paste code from the SQL window in the query builder, there are
so many () I usually head to the "Where" clause and remove them simply
so I can read it easily. Usually the where clause is strung together by
ANDs. The only time I need tha parans is when you have ORs mixed in the
clause.

I was assuming your Combos use numbers. If not, you can add the quotes
as necessary.

Instead of
strFilter = strFilter & "Site = " & Me.Combo20 & " And "
you could use
strFilter = strFilter & "Site = '" & Me.Combo20 & "' And "

Salad <oi*@vinegar.com> wrote:

arthur-e wrote:
Thanks in advance!! I've looked at fConcatFld but that doesn't seem to
be what i'm looking for or I just can't figure it out.

I'm trying to have a button select records based on two combo boxes -
one holding a number and one text.
Floor(combo18) is a floor number and site(combo20) is a building
name

Private Sub Command22_Click()
Dim strSQL As String
strSQL = "Select * FROM [qryAllSlrSites]"

strSQL = strSQL & "WHERE ((([qryAllSlrSites].[Exclude])=False) AND
((qryAllSlrSites.Floor)=" & Me.Combo18 & "))"

strSQL = strSQL & " AND ((qryAllSlrSites.site)= '" & Me.Combo20 & "))"

Me.RecordSource = strSQL
End Sub

Is there a good way to make do this? I've been cutting and pasting
SQL statements trying to put fields in where criteria were in the
statement.

-warning e-mail address altered- arthureNOSPACE@


Hmmmm...I might put in the after update event some code like
SetFilter
for each combo box.

THen create a routine

PRivate Sub SetFilter()
Dim strFilter As STring
If Not IsNull(Me.Combo18) Then
strFilter = "Exclude = False And "
"Floor = " & Me.Combo18 & " And "
ENdif

If Not IsNull(Me.Combo20) Then
strFilter = strFilter & _
"Site = " & Me.Combo20 & " And "
ENdif

If strFilter > "" Then
'remove the word And
strFilter = Left(strFilter,Len(strFilter) -5)
Me.Filter = strFilter
Me.FilterOn = True
Else
'no filter
Me.Filter = ""
Me.FilterOn = False
ENdif
ENd SUb

strSQL = strSQL & " AND ((qryAllSlrSites.site)= '" & Me.Combo20 & "))"


-warning e-mail address altered- arthureNOSPACE@

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jonas Galvez | last post by:
Is it true that joining the string elements of a list is faster than concatenating them via the '+' operator? "".join() vs 'a'+'b'+'c' If so, can anyone explain why?
7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
24
by: Caroline | last post by:
The following is not working int num = 0, char *string; string = "qwerty"; strcpy(string, num); strcpy(string, ".png");
35
by: michael.casey | last post by:
The purpose of this post is to obtain the communities opinion of the usefulness, efficiency, and most importantly the correctness of this small piece of code. I thank everyone in advance for your...
23
by: Bonj | last post by:
what is the correct form of string concatenation in VB.NET, + or &? Both seem to work, but which is correct? I know it's + in C# and & in VB6, but which in VB.NET?
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
34
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ...
2
by: Bart Kastermans | last post by:
Summary: can't verify big O claim, how to properly time this? On Jun 15, 2:34 pm, "Terry Reedy" <tjre...@udel.eduwrote: Thanks for the idea. I would expect the separation to lead to somewhat...
34
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.