473,396 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Form field used as criteria for query

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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub VIEW_NewRate_Click()
  2. On Error GoTo Err_VIEW_NewRate_Click
  3.     Dim MyDB As DAO.Database
  4.     Dim i As Integer
  5.     Dim vs As String
  6.     Dim strSQL As String
  7.     Dim strWhere As String
  8.     Dim strIN As String
  9.     Dim flgSelectAll As Boolean
  10.     Dim varItem As Variant
  11.     Dim rstTempTbl As New ADODB.Recordset
  12.  
  13.     If FNU_Choice.ItemsSelected.Count = 0 Then
  14.         MsgBox "You must make a selection(s) from the list" _
  15.                , , "Selection Required !"
  16.     Else
  17.         vs = ConnectSelected(FNU_Choice, ",", 0)
  18.         'Field referenced in query
  19.         Me.Criteria = vs
  20.         DoCmd.OpenQuery "Benefit_Rate_Summary - View NEW Rate", acViewNormal
  21.  
  22.     End If
  23.     'Clear listbox selection after running query
  24.     For Each varItem In Me.FNU_Choice.ItemsSelected
  25.         Me.FNU_Choice.Selected(varItem) = False
  26.     Next varItem
  27.  
  28.  
  29. Exit_VIEW_NewRate_Click:
  30.     Exit Sub
  31.  
  32. Err_VIEW_NewRate_Click:
  33.         'Write out the error and exit the sub
  34.         MsgBox Err.Description
  35.         MsgBox Err.Number
  36.         Resume Exit_VIEW_NewRate_Click
  37.  
  38. End Sub
  39.  
  40. Public Function ConnectSelected(ListName As ListBox, _
  41.                         Optional ByVal sDelimiter As String = ",", _
  42.                         Optional ByVal iColumn As Integer = 0) As String
  43.  
  44.    Dim sConnect   As String
  45.    Dim vID        As Variant
  46.    Dim v          As Variant
  47.  
  48.    If ListName.ColumnCount <= (iColumn - 1) Then
  49.       Err.Raise vbObjectError + 1501, , "The specified column doesn't exist."
  50.    End If
  51.  
  52.    For Each v In ListName.ItemsSelected
  53.       vID = ListName.Column(iColumn, v)
  54.       sConnect = sConnect & CInt(vID) & sDelimiter
  55.    Next v
  56.  
  57.    If Len(sConnect) Then
  58.       ConnectSelected = Left(sConnect, (Len(sConnect) - Len(sDelimiter)))
  59.    Else
  60.       ConnectSelected = ""
  61.    End If
  62.  
  63. End Function
THANK you for the help
Mar 31 '10 #1

✓ answered by ziccardi

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
Stewart Ross
2,545 Expert Mod 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. 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
Apr 5 '10 #2
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.
Apr 5 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
2
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...
4
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...
2
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...
2
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 ...
3
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...
5
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...
10
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...
10
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.