473,387 Members | 1,693 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,387 software developers and data experts.

Requery subform issue

46
Hello,

I have created a form that allows the user to search a sales table with the option to choose 1) a sales representative and 2) a car type matching any portion of the inputted text. For example, you can choose "Joe Smith" as your salesman and type "mus" in the search box and all sales by Joe Smith selling a Mustang or a Mustafa (if such a goofy name for a car existed) would return.

The problem I am running into is with the subform on the form, which is supposed to display the results of the query. The code (below) instructs the subform to requery but it doesn't seem to be working.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command9_Click()
  2. Dim db As Database
  3. Dim qdf As QueryDef
  4. Dim strsql As String
  5.  
  6. Set db = CurrentDb
  7.  
  8. strsql = "SELECT [sales_rep], [sale_id], [automobile], [sale_price]" & _
  9. "FROM automobile_sales " & _
  10. "WHERE [automobile] Like '*' & '" & Me.automobile_search & "' & '*' AND [sales_rep]=[Forms]![Sale_Search]![associate];"
  11.  
  12. db.QueryDefs.Delete "tmp_qry"
  13. Set qdf = db.CreateQueryDef("tmp_qry", strsql)
  14.  
  15. me.sale_search_subform.requery
  16.  
  17. End Sub
Any ideas as to why the final line of code (requery) doesn't seem to be working?

Thank you very much in advance!
Mar 18 '08 #1
2 1953
Stewart Ross
2,545 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. ...Set qdf = db.CreateQueryDef("tmp_qry", strsql)
  2.  
  3. me.sale_search_subform.requery
  4.  
  5. End Sub
Hi. The querydef has no relation to the subform. What you have done is to create a new query; doing so does not filter or alter your subform in any way. You can either (1) apply a filter to your subform, or (2) set the subform's recordsource to be your new query.

Option 1 is simpler; you just filter using the WHERE clause in line 10 without the word WHERE. To do so with a string called strWhere created from your current WHERE clause (but without the word WHERE!) you would set the filter property of your subform as follows:
Expand|Select|Wrap|Line Numbers
  1. me.sale_search_subform.Form.Filter = strWhere
  2. me.sale_search_subform.Form.FilterOn = True
Alternately, to set its recordsource to strSQL:
Expand|Select|Wrap|Line Numbers
  1. me.sale_search_subform.Form.RecordSource = strSQL
-Stewart
Mar 18 '08 #2
bbatson
46
Thank you so much. I opted to use the second option you provided, which works very well. Thank you again!
Mar 18 '08 #3

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

Similar topics

2
by: David B | last post by:
I am populating an unbound text box from datepicker calender. After the date has been selected I need the sub form to requery. If I manualy put a date in the text box the after update works fine...
6
by: Tim Marshall | last post by:
Here's the situation. A form, frmSetUp, with a subform control called subExplain with a source object form frmSetUpSubDefineSides. The source object is a bound form, displaying a few records, no...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
14
by: Kurt | last post by:
I have an unbound main form with an unbound subform. frmProjects fsubProjectList Using combo boxes, the user can select several search criteria on frmProjects and then click a command button....
1
by: Parasyke | last post by:
I have a subform within a tabpage that will requery/refresh (?) if I press F9 and it will update the data in the subform, but I have tried various combinations of Me!SubformName.requery...
4
by: midlothian | last post by:
Hello, I have conditional formatting set up on a subform based on a calculated value in the underlying query. For instance, if Sales are >$1000, the query displays "Yes," otherwise it displays...
1
by: Stinky Pete | last post by:
Hi everyone, I have been updating a file that uses a main form that contains a subform (as a datasheet). The main form really does not do anything on opening except maximizes to the users...
11
by: mrowe | last post by:
I am using Access 2003. (I am also using ADO in the vast majority of my code. I recently read a post that indicated that ADO is not all that is was initially cracked up to be. In the back of my...
31
by: matthewslyman | last post by:
I have an unusual design and some very unusual issues with my code... I have forced Access to cooperate on everything except one issue - record deletion. My form design involves a recursively...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.