问题描述
您好。我正在使用Access 2013,我搜索了高低;在书籍,互联网和YouTube视频中找到了数十亿的答案;那么现在我只是请求帮助,请?
Hi. I'm using Access 2013, and I have searched high and low; found billions of answers in books, internet, and youtube videos; and, so now am just flat out asking for help, Please?
我正在使用VBA for Access为名为 OmniQ的查询设置自定义SQL。
我想要包含以下短语:
I'm using VBA for Access to set custom SQL for a Query named OmniQ. I would like to include the phrase:
赞" *" &安培; [表格]![SearchF]![txtDesc]& "*"<
Like "*" & [Forms]![SearchF]![txtDesc] & "*"
使用VBA进入SQL;但是,无论我尝试什么,VBA都不会这样做。我试过用%代替。我尝试过使用* [*] *。我花了好几个小时试图解决这个问题。这是整个VBA到SQL代码:
into the SQL using VBA; however, no matter what I try VBA won't do it. I've tried using % instead. I've tried using *[*]*. I've spent hours trying to figure this out. Here's the overall VBA to SQL code:
strSQL =" SELECT TOP 1 Omni.Genre,Omni.Show,Omni.Season,Omni.Episode,Omni。[Episode Name],Omni .Char1,Omni.Char2,Omni。[综合评级],Omni。[Kenyx Fav],Omni。[Digit Fav],Omni.Description" &安培; _
"FROM [Omni] " &
"WHERE(((Omni.Description)Like" *"& [Forms]![SearchF]![txtDesc]&" *"))& _
"ORDER BY Rnd(Omni.ID);"
strSQL = "SELECT TOP 1 Omni.Genre, Omni.Show, Omni.Season, Omni.Episode, Omni.[Episode Name], Omni.Char1, Omni.Char2, Omni.[Combined Rating], Omni.[Kenyx Fav], Omni.[Digit Fav], Omni.Description " & _
"FROM [Omni] " &
"WHERE (((Omni.Description) Like "*" & [Forms]![SearchF]![txtDesc] & "*")) & _
"ORDER BY Rnd(Omni.ID);"
如你所见,我有多个字段,我只拉1条记录( &随便那个)。这给了我"语法错误"。 * [*] *给我"..找不到| 1字段......"。 %给了我"语法错误。"
As you can see I have multiple fields, am only pulling 1 record (& Randomly at that). This gives me "Syntax Error". The *[*]* gives me "..can't find |1 field...". The % gives me "Syntax Error."
我做错了什么,拜托?
推荐答案
我认为它可能是
" WHERE(((Omni.Description)喜欢"" *"& [Forms]![SearchF]![txtDesc]&" *""))"
"WHERE (((Omni.Description) Like ""*" & [Forms]![SearchF]![txtDesc] & "*"" )) "
我们需要使用"""代表"在VBA中的字符串中。
We need to use "" to represent " in the string in VBA.
问候,
Celeste
这篇关于SQL到VBA - 表观语法不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!