Re: Syntax of SQL in VB

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

fredg_at_example.invalid
Date: 02/02/04


Date: Mon, 02 Feb 2004 15:24:46 GMT

On Mon, 2 Feb 2004 06:59:28 -0800, "Carlos"
<anonymous@discussions.microsoft.com> wrote:

>I'm using an onUpdate event to determine the rowsource of
>a combo box based on a selection in another combo box.
>e.g. I choose Honda in one combo box and Honda models
>become the rowsource in the next combo box. My table
>contains three fields: system, application, and detail.
>This particular form is associated to a particular system,
>while the first combo box lists the applications, and the
>the second combo box should list the details associated
>with the application selected in the first box.
>Below is the event code that I've tried. Note the use of
>the variable strCategory in the SQL statement.
>
>Private Sub Combo0_AfterUpdate()
>Dim strCategory As String
>
>strCategory = [Combo0]
>
>Me!Combo2.RowSource = SELECT Category.detail FROM Category
>WHERE (((Category.system)="ABC") AND ((Category.category)
>="strCategory"));
>
>End Sub
>
>This code does not work. The trick I can't manage, I
>believe, is in the use of quotation marks to fit the SQL
>statement into the module.
>Could someone please guide me in the exact syntax.
>
>Thank you,
>
>Carlos

Carlos,

No need for the strCatagory variable.

1) If the Bound column of Combo0 is a Number datatype:

Me!Combo2.RowSource = "SELECT Category.detail FROM Category
WHERE Category.system= 'ABC' AND Category.category = " & Me!Combo0 & "
Order By Category.Detail;"

2) If the Bound column of Combo0 is a Text datatype:

Me!Combo2.RowSource = "SELECT Category.detail FROM Category
WHERE Category.system= 'ABC' AND Category.category = '" & Me!Combo0 &
"' Order By Category.Detail;"

Note.. the entire SQL is a string and must be within quotation marks.
Therefore text within the quoted string (ABC and the value of
Me!Combo0) must be delimited using single quotes (').
I added an Order By clause to sort the combo box. If you do not wish
it sorted, don't add it, but keep the semicolon.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal email


Relevant Pages

  • Injecting a variable attribute from a select grid control
    ... I'm very new to asp.net and very green with programming in general. ... an individual can make a selection from a data grid view. ... variable into SQL string, which is a attached to a SQLDataSource ... success in taking the value of the selection, placing it into the SQL ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: updating to a table
    ... "Jimenda" wrote in message ... > selection in each box, and then ... Debug.Print SQL ... The challenge is in getting a string built up that results in a valid SQL ...
    (microsoft.public.access.forms)
  • Re: Multiple checkbox Query
    ... selected from multiple checkboxes on the Web form. ... I am using the string in a ASP page with the SQL statement: ... This works fine with one checkbox selection, ...
    (microsoft.public.sqlserver.programming)
  • Re: BrowseForFolder
    ... WinXp and a for root file selection in Win2k. ... present on all installations and is exposed through the comdlg32.ocx file. ... UserOpenDlg.initialDir= string ...
    (microsoft.public.scripting.vbscript)
  • Re: Exporting excel to text file
    ... filenumber is just a new local variable which is going to hold the system ... >> Thank you so much for your help, the While statement and empty is ... The selection may very large as compared to what is ... >> 'Walk down each row and include it in the string if the cell is not ...
    (microsoft.public.excel.misc)