Consulting

Results 1 to 8 of 8

Thread: SQL Select *

  1. #1

    SQL Select *

    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[VBA]'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[/VBA] 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.

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

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    SQL % = *
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Hi SamT,

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

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    SQL code
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    By the way your first code is flawed since you use tb as the variable then check if ctl is empty.
    Be as you wish to seem

  6. #6
    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.

  7. #7
    strSQL = "SELECT A,b,c " & _
    strSQL = strSQL & "GROUP BY A,b,c" & _
    [vba]'txtbox1 sql statement
    If Worksheets("GUI").txtbox1.Value = " * " Then
    strSQL2 = "SELECT Unique A " & _
    "FROM D"
    Else
    strSQL = strSQL & "WHERE (A)='" & a & "' "
    End If[/vba]

    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.

  8. #8
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    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
    [vba]if len(tb.object.text) = 0 then[/vba]
    Be as you wish to seem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •