PDA

View Full Version : SQL Select *



purplesky
04-08-2013, 07:40 PM
Hi,
I have multiple textboxes. Let say I give my users to key in any data in textboxes then I will retrieve them from Ms Access. I have a code to check for blank'checking for every empty textbox.
For Each tb In ActiveSheet.OLEObjects
If TypeName(tb.Object) = "TextBox" Then
If ctl = Empty Then
MsgBox ("Please enter * to retrieve all")
Exit Sub
End If
End If
Next tb get by some website.
my question is if user key in "*" then SQL will select unique from that column, means select all for 1 column.

"AND (PS_DWH_ADMIN.DWH_WIP_DATA_YEAR.PROCESS_CLASS)='" & c & "' " & _
"AND (PS_DWH_ADMIN.DWH_WIP_DATA_YEAR.PRODUCT_TYPE)='" & d & "' " & _
I have something like this in my excel vba code where c or d = sheets.txtbox.value.
thanks

SamT
04-09-2013, 12:28 AM
SQL % = *

purplesky
04-09-2013, 12:43 AM
Hi SamT,

the SQL % = * put inside SQL or on the code checking for empty textbox?

SamT
04-09-2013, 01:08 AM
SQL code

Aflatoon
04-09-2013, 07:45 AM
By the way your first code is flawed since you use tb as the variable then check if ctl is empty. ;)

purplesky
04-09-2013, 06:35 PM
Hi, samT

well, I still couldn't get what you mean as it still error when I put it inside.
where is the exact location I need to put in my sql? thanks for your reply.

Aflaton: it works if I put ctl while it doesn't work if I replace it tb. I get codes from sm other place.

purplesky
04-09-2013, 07:31 PM
strSQL = "SELECT A,b,c " & _
strSQL = strSQL & "GROUP BY A,b,c" & _
'txtbox1 sql statement
If Worksheets("GUI").txtbox1.Value = " * " Then
strSQL2 = "SELECT Unique A " & _
"FROM D"
Else
strSQL = strSQL & "WHERE (A)='" & a & "' "
End If

the sql statement is follow by the if statement.

Can I write like this to retrieve data from Access?
I want to retrieve the data according to user key in which I set is as variable a from txtbox value, If user key in"*" I want to select all data from that particular column.

Aflatoon
04-09-2013, 11:17 PM
Based on the code you posted ctl is an undeclared variant and would always be Empty so perhaps you have it declared elsewhere, but it still does not appear to relate to your loop which should use something like
if len(tb.object.text) = 0 then