You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

使用组合框链接子窗体时遇3464数据类型不匹配错误求助

Fixing Data Type Mismatch Error 3464 with Combo Box Linked Subform

Hey there, that 3464 error is almost always a type mismatch in your SQL string—let's get this sorted quickly!

The Root Cause

Your Drawingno field in tbl_welddata is almost certainly a text data type, but when you built your SQL query, you didn't wrap the value from Me!CboDrawingno in single quotes. Access tries to interpret that unquoted value as a number, which clashes with the text field, hence the mismatch error.

Quick Fix: Wrap Text Values in Single Quotes

Update your code to add single quotes around the combo box value:

Dim mydrawing As String
' Add single quotes around the text value to match the field type
mydrawing = "select * from tbl_welddata where [Drawingno] = '" & Me!CboDrawingno & "'"
Me.tbl_welddatasubform.Form.RecordSource = mydrawing
Me.tbl_welddatasubform.Form.Requery

Better Practice: Use Parameter Queries (Avoids SQL Injection & Type Issues)

For more robustness (and to prevent accidental SQL injection if your combo box allows user input), use a parameterized query instead of string concatenation:

Dim qdf As QueryDef
Dim strSQL As String

' Define SQL with a named parameter
strSQL = "SELECT * FROM tbl_welddata WHERE [Drawingno] = [SelectedDrawing]"

' Create a temporary query definition
Set qdf = CurrentDb.CreateQueryDef("", strSQL)
' Assign the combo box value to the parameter (Access handles type conversion automatically)
qdf.Parameters("[SelectedDrawing]").Value = Me!CboDrawingno

' Set the subform's recordset to the parameterized query results
Set Me.tbl_welddatasubform.Form.Recordset = qdf.OpenRecordset()

' Clean up
Set qdf = Nothing

Quick Checks to Rule Out Other Issues

  • Double-check that your combo box CboDrawingno is returning the correct value: if it's bound to a hidden ID column instead of the Drawingno text, use Me!CboDrawingno.Column(0) (columns are 0-indexed) to get the text value.
  • Confirm the data type of Drawingno in tbl_welddata matches the value you're passing (text vs. number).

内容的提问来源于stack exchange,提问作者mak

火山引擎 最新活动