logo
search
VBA & Macro Problems

Fix Access ComboBox Value Not Passed to VBA Procedure

Maira MehtabMaira Mehtab Sep 22, 2026 870 views

Question details

The user needs to correctly pass a ComboBox value from a form into a VBA procedure to construct a SQL statement without triggering an error.

Product
Microsoft Access
Device & OS
not provided
Scenario
Building a SQL WHERE clause dynamically in a VBA procedure using the selected value from a form's ComboBox.
Observed behavior
The Access form fails or the query crashes because the ComboBox value is inserted into the SQL statement without the correct delimiters for its specific data type.
Before you start

Verify the data type of the bound column in your ComboBox, as text values require single quotes in SQL, while numeric values do not.

Solution 1Recommended

Use Correct Delimiters for Text Values in SQL

Fix the VBA syntax error by wrapping text values retrieved from the ComboBox in single quotation marks within the SQL string.

When dynamically building a SQL query in VBA, any string (text) parameter must be enclosed in single quotes. If the ComboBox value is text and you omit these quotes, the database engine cannot interpret the WHERE clause properly, resulting in a syntax or data type mismatch error.

1
Identify the ComboBox value data type

Open your Access form in Design View, select the ComboBox, and check its Row Source to confirm if the bound column contains text or numbers.

2
Add single quotes for text values

In your VBA procedure, wrap the ComboBox reference in single quotes. For example: strSQLStatement = "SELECT * FROM tblMolds WHERE tblMolds.[Type] = '" & txtMoldType & "'"

3
Omit quotes for numeric values

If the ComboBox returns a numeric ID, do not use quotes. Use this format instead: strSQLStatement = "SELECT * FROM tblMolds WHERE tblMolds.[ID] = " & txtMoldType

Free Microsoft Office alternative

Need a Powerful, Lightweight Office Suite? Try WPS Office

While Microsoft Access is designed for complex relational databases, WPS Office provides an exceptional, free alternative for your everyday document, spreadsheet, and presentation tasks. It offers robust VBA and macro support in its Spreadsheet tool, allowing you to automate data processing with ease.

  1. 1. Download the installer: Visit the official WPS Office website and download the free installer for your operating system.
  2. 2. Install the software: Run the setup file and follow the on-screen instructions to complete the installation.
  3. 3. Open WPS Spreadsheet: Launch WPS Spreadsheet to begin writing and executing your VBA macros immediately.
Seamless format compatibility with Microsoft Excel, Word, and PowerPoint.Advanced Spreadsheet application with comprehensive built-in VBA and macro support.Lightweight architecture that consumes significantly fewer system resources.Free to use with a familiar, tabbed user interface for effortless migration.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a 'Data type mismatch in criteria expression' error in Access VBA?

This error typically happens when you fail to use the correct SQL delimiters for the data type being passed. For instance, passing a text value from a ComboBox without wrapping it in single quotes (' '), or passing text into a numeric database field.

How do I format date values passed from a ComboBox in an Access SQL string?

Date values in Access SQL must be enclosed in hash tags (#). For example, your VBA code should look like: "SELECT * FROM tblEvents WHERE EventDate = #" & Me.cboDate.Value & "#".

How can I populate a subform using the results of my new VBA SQL query?

After successfully building your SQL statement with the correctly delimited ComboBox value, you can assign it to the subform's record source using: Me.YourSubformControlName.Form.RecordSource = strSQLStatement, followed by Me.YourSubformControlName.Form.Requery.