How to create SQL Statement from Combobox Selections

This video will show you how to
use checkboxes to create a SQL statement
and formulate a recordsource for a form.

In the sample database, a certain product can
be combined with other products to create a package.

We want to select the products belonging to each
package.

In this video you will be shown how to
see the products for the selected basket

Concepts discussed:

combobox
subform
sql form recordsource
disconnected form
command button action

Option Compare Database

'========================================================
'DATABASE DESIGNED & CODED BY LOEBLCOM SERVICES 2013
'ERIK LOEBL(713)409-7041
'EMAIL: erik@loeblcomservices.com
'WEB:   http://loeblcomservices.com
'========================================================


Private Sub btnSelectItems_Click()
    Dim strField As String
    Dim strSQL As String
        
    strField = Me.cboChoices
    
    
    strSQL = "SELECT product_name, " & strField & " FROM products WHERE " & strField & " = TRUE"
    
    Me.frmBasketItemsSub.Form.RecordSource = strSQL
    
    Me.frmBasketItemsSub.Form("txtProducts").ControlSource = strField
    Me.frmBasketItemsSub.Form("lblSelected").Caption = strField
        
        
End Sub

Click here for more information on comboboxes and filter related posts.

Click here for the file:
How-to-create-SQL-Statement-from-Combobox-Selections.accdb

Offsite Related Information:

“Go Fund Me” Page


($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Facebooktwitterredditpinterestlinkedinmailby feather
Tags: , , , , ,