Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: SQL Server
Expertise: Beginner
Jun 28, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

SQL and Using Text and Combo Boxes

I write a statement such as
frmStatistics.datStatistics.RecordSource = "SELECT * FROM tblSpecialGroup Where Sex = 'M' AND Date BETWEEN '" & "051099" & "'" & " And " & "'" & "051499" & "'". 
This statement draws up records from my database that are Male and between the dates of 5-10-99 and 5-14-99 on an MSFlexGrid. Well, I want to enter the data from text boxes and combo boxes instead of putting the data in the code. Such as this statement:
frmStatistics.datStatistics.RecordSource = "SELECT * FROM tblSpecialGroup Where Sex = '" & Trim(cboDate(1).Text) & "'"
Well, both statements work, but what I'm having trouble with is making a statement that has a combo box for Sex and 2 text boxes for Date (so that the user can enter from 5-2-99 to 9-3-99 and so on). How do I make the statement to work with the SQL with the text boxes for date and combo box for sex? Here is my attempt (I have made many, but none of them work):
frmStatistics.datStatistics.RecordSource = "SELECT * FROM tblSpecialGroup Where Date BETWEEN '" & trim(txtdate1.Text) & "'" & " And " & "'" & trim(txtdate3.Text)& "'" & "'" AND Sex = '" & trim(cbogender.text) & "'"
Genie Applebury Tinytimer@hotmail.com

It seems to me that what is needed is a query parameter selection form part of this application; a place where the user enters in the things they are going to search for, then get them and process it. Is the datatype for sex also character or is it something like 1= male and 2 = female?

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date