您的数据包含换行符,并且组合框每条记录仅显示一行。
要显示数据,您可以替换行源中的换行符。
SELECT Replace([CustomerName],vbCrLf, " ") as CName FROM table
' vbCrLf is the VBA constant for linebreaks (Cr - Carrige Return, Lf - LineFeed)
这是糟糕的数据库规范化(假设您要搜索与城市相同的客户名称,例如巴黎)。每行应该是表中的一个单独字段(以及邮政编码)。如果每个数据都有换行符(例如没有街道 -> 空行),您可以将数据拆分到新字段中。
'Put this code in a module
'Split function
Public function splitCustomerName(ByVal strCustomerName as String, ByVal index as long) as String
Dim arrCustomerName As Variant ' or declare a fixed array if you know the number of lines
arrCustomerName = Split(strCustomername,vbCrLf)
splitCustomerName = arrCustomerName(index)
End Function
查询
UPDATE table SET newCustomerName = splitCustomerName([table].[CustomerName],0)
, newCustomerStreet = splitCustomerName([table].[CustomerName],1)
, newCustomerCity = splitCustomerName([table].[CustomerName],2);
只需为名称、街道和城市创建必要的列,然后运行查询。
如果您删除 CostumerName 列并重命名表(例如 newTable),您可以使用表的旧名称创建查询,其行为类似于旧表。
SELECT *
, newCustomerName & vbCrLf & newCustomerStreet & vbCrLf & newCustomerCity as CustomerName
FROM newTable