With Warm Regards,
Art – You state that the combo box value is a string. All strings must be qualified with either single or double quotes. I tend to use double quotes to avoid stumbling over words like O'Hara. But even then you might get a set of double quotes. To fix that I use Chr(34).
Dim strSQL as String
strSQL = "Select MainTitle.MainTitleKey, MainTitle.MainLevelTitle FROM MainTitle " & _
"WHERE ArchiveKey = " & Chr(34) & Me.cmbCurrentECabinet.Value & Chr(34) & " ORDER BY MainLevelTitle"
Debug.Print strSQL
[Breakpoint Here]-->Me.cmbCurrentEFolder.RowSource = strSQL
Note you had one ending single quote but not one at the beginning of the string. Also you lacked a space before "Order By".
When you build a SQL string that isn't working properly the best way to debug it is to put a break point on the line right after the string. Then put a line before the breakpoint that reads:
Debug.Print
That will print the string exactly as the compiler sees it. Paste that in a query SQL window and run it to see what happens.
Regards,
Bill
From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Sunday, November 05, 2017 8:03 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Order By Issue
Can some on help parse this string correctly:
Me.cmbCurrentEFolder.RowSource = "Select MainTitle.MainTitleKey, MainTitle.MainLevelTitle FROM MainTitle " & _
"WHERE ArchiveKey = " & Me.cmbCurrentECabinet.Value & "'" & "ORDER BY MainLevelTitle"
When I run this it is concatenating the Order By with the value from the combo box...
The value in the combo box is a string...
Thank you,
Art Lorenzini
Sioux Falls, SD
Posted by: Art Lorenzini <dbalorenzini@yahoo.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (3) |
Tidak ada komentar:
Posting Komentar