When my query is executed it produces no results. However, if I copy and paste the criteria from the information populated and referenced in my query, it works fine.
The criteria needs to be numbers. eg. In (1,2) The text in my criteria field is:
In ([Forms]![frm_RateLoad]![Criteria])
Here is the code: - Private Sub VIEW_NewRate_Click()
-
On Error GoTo Err_VIEW_NewRate_Click
-
Dim MyDB As DAO.Database
-
Dim i As Integer
-
Dim vs As String
-
Dim strSQL As String
-
Dim strWhere As String
-
Dim strIN As String
-
Dim flgSelectAll As Boolean
-
Dim varItem As Variant
-
Dim rstTempTbl As New ADODB.Recordset
-
-
If FNU_Choice.ItemsSelected.Count = 0 Then
-
MsgBox "You must make a selection(s) from the list" _
-
, , "Selection Required !"
-
Else
-
vs = ConnectSelected(FNU_Choice, ",", 0)
-
'Field referenced in query
-
Me.Criteria = vs
-
DoCmd.OpenQuery "Benefit_Rate_Summary - View NEW Rate", acViewNormal
-
-
End If
-
'Clear listbox selection after running query
-
For Each varItem In Me.FNU_Choice.ItemsSelected
-
Me.FNU_Choice.Selected(varItem) = False
-
Next varItem
-
-
-
Exit_VIEW_NewRate_Click:
-
Exit Sub
-
-
Err_VIEW_NewRate_Click:
-
'Write out the error and exit the sub
-
MsgBox Err.Description
-
MsgBox Err.Number
-
Resume Exit_VIEW_NewRate_Click
-
-
End Sub
-
-
Public Function ConnectSelected(ListName As ListBox, _
-
Optional ByVal sDelimiter As String = ",", _
-
Optional ByVal iColumn As Integer = 0) As String
-
-
Dim sConnect As String
-
Dim vID As Variant
-
Dim v As Variant
-
-
If ListName.ColumnCount <= (iColumn - 1) Then
-
Err.Raise vbObjectError + 1501, , "The specified column doesn't exist."
-
End If
-
-
For Each v In ListName.ItemsSelected
-
vID = ListName.Column(iColumn, v)
-
sConnect = sConnect & CInt(vID) & sDelimiter
-
Next v
-
-
If Len(sConnect) Then
-
ConnectSelected = Left(sConnect, (Len(sConnect) - Len(sDelimiter)))
-
Else
-
ConnectSelected = ""
-
End If
-
-
End Function
THANK you for the help
I need the query to be easily updatable, so I do not think that using sql will work. The query itself is pretty complex with many joins. Anyway, I changed my approach and populate the information to another table. I connected this table in the query to the field instead of using criteria. It seems to be working great. Thank you for your response.
2 1948
Hi ziccardi. Are you executing the query in code? If you are, the In statement will not work as you have it at present. If you have defined the SQL for the query as a string you would need to split the string to include the value of your form control, not a reference to the control itself, like this: - strSQL = strSQL & "WHERE [yourfield] In (" & [Forms]![frm_RateLoad]![Criteria] & ")"
I'm not sure what relevance the VBA code you posted has to your problem. If the query is not returning any results when you run it but it does from the query editor then the query and how it is constructed is the bit we need to see!
-Stewart
I need the query to be easily updatable, so I do not think that using sql will work. The query itself is pretty complex with many joins. Anyway, I changed my approach and populate the information to another table. I connected this table in the query to the field instead of using criteria. It seems to be working great. Thank you for your response.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve |
last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's
criteria is set ats:
Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the
selections are 30, 60...
|
by: neptune |
last post by:
I built a form to access a query with a 2 field primary key. It
should use 2 controls to find the unique record and display the other
field values on the form. In the criteria section of the...
|
by: James |
last post by:
Dear group,
Can anyone tell me how to do the following?
I have a basic list of numbers in a table
I want to be able to search these by letting the user type "<10" or
">=50" on a simple form...
|
by: RBohannon |
last post by:
I have a report with most fields populated by a query. However, some
of the fields are variable in such a way that their values cannot be
queried from a table. At present the values for these...
|
by: Sherman H. |
last post by:
I have a few questions for crosstab and popup form questions:
1. I created a crosstab as follows:
IT Financial Operation
John 21 22 ...
|
by: Matthew |
last post by:
I am trying to build a form that has certain criteria on it (combo
boxes) which a user can pick from a range of values to specify the
criteria he wants when he runs a query on the form. I am...
|
by: tdmailbox |
last post by:
I have a form with a child form. In the child form there is a list of
names that can grow quite large. On the parent form I want to display
the first name from the child form. I set up a test...
|
by: motessa |
last post by:
Hello All,
I am new to Access and have been looking for answers to my problem on
the internet and have not found it yet. I hope someone can give me a
hint. Thanks so much.
I have a form...
|
by: sesling |
last post by:
I have created a query that will pull information from our database for the operators. This query will pull in on average 50,000 records. The operators need to refine the search results. I have...
|
by: tomlebold |
last post by:
Having problems displaying query results from combo boxes on a sub
form, which is on the same form that is used to select criteria.
This has always worked form me when displaying query results on...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |