473,406 Members | 2,705 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,406 software developers and data experts.

How can I refresh a sub form

I have two subforms in my main form.
In the main form I want the user to select a customer, class, and date range.
The 2 subforms are similar. One is the history records in the recent past and the other is future records. The user has to input a passenger forecast for the customer for the selected class for each record in the date range.
The subforms are populated by a query which is altered according to their selection.
I wish to refresh the subform after changing the queries as part of the main form field's _click subroutine. The UpdateForecastPax.Requery where UpdateForecastPax is the query does not seem to work.

I can't see how to link the form and subform as both are queries of the same table rather than different tables. Is there a command or commands which will force a subform to refresh with the changed query?

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtAirline_Click()
  2.  
  3.     Airline_set = 1
  4.  
  5.     Call ReDoFlightList
  6.     cmbFlight.SetFocus
  7.  
  8. End Sub
  9. Public Sub ReDoFlightList()
  10.  '  This Sub checks all 3 selections and re-creates the UpdateForecastPax and HistoryForecastPax query
  11. On Error GoTo Err_ReDoMenuList
  12.  
  13. Dim temp As String
  14. Dim db As Database
  15. Dim sSQL1 As String
  16. Dim sSQL As String
  17.     Set db = CurrentDb
  18.     ' Refresh Querydefs collection
  19.     db.QueryDefs.Refresh
  20.     ' If MenuIdSelect query exists delete it.
  21.     For Each qrytemp In db.QueryDefs
  22.         If qrytemp.Name = "HistoryForecastPax" Then
  23.            db.QueryDefs.Delete qrytemp.Name
  24.         ElseIf qrytemp.Name = "UpdateForecastPax" Then
  25.            db.QueryDefs.Delete qrytemp.Name
  26.         End If
  27.     Next qrytemp
  28.     ' Add to HistoryForecastForm Customer Flight and Class
  29.     sSQL = "SELECT ForecastMealsMaster.Customer, ForecastMealsMaster.Flight,ForecastMealsMaster.Class,"
  30.     sSQL = sSQL & "ForecastMealsMaster.Flight_Date , ForecastMealsMaster.Aircraft_Type, "
  31.     sSQL = sSQL & "ForecastMealsMaster.Origin, ForecastMealsMaster.Destination,"
  32.     sSQL = sSQL & "ForecastMealsMaster.Forecast_Pax, ForecastMealsMaster.Actual_Pax,"
  33.     sSQL = sSQL & "ForecastMealsMaster.Fpax_ShortTerm, ForecastMealsMaster.Fpax_LongTerm,"
  34.     sSQL = sSQL & "ForecastMealsMaster.FConfig, ForecastMealsMaster.ActualConfig,"
  35.     sSQL = sSQL & "ForecastMealsMaster.LastWkAvgPax, ForecastMealsMaster.LyPax, ForecastMealsMaster.LastWkPax,"
  36.     sSQL = sSQL & "ForecastMealsMaster.Last2WkPax, ForecastMealsMaster.comment,"
  37.     sSQL = sSQL & "[Actual Pax Last update date].LastUpdateDate"
  38.     sSQL = sSQL & " FROM ForecastMealsMaster, [Actual Pax Last update date]"
  39.     sSQL = sSQL & " WHERE ((ForecastMealsMaster.Flight_Date) Between NOW()-30"
  40.     sSQL = sSQL & " AND [Actual Pax Last update date].LastUpdateDate ) "
  41.  
  42. sSQL1 = " "
  43. ' Add code for Airline
  44.     If Airline_set > 0 Then
  45.         txtAirline.SetFocus
  46.         If txtAirline.Value <> "" Then    ' Has a value
  47.             sSQL1 = sSQL1 & " AND ForecastMealsMaster.Customer LIKE " & """*"
  48.             sSQL1 = sSQL1 & txtAirline.Value & "*"""
  49.         End If
  50.     End If
  51. ' Add code for Class
  52.     If A_Class_set > 0 Then
  53.         cmbClass.SetFocus
  54.         If cmbClass.Value <> "" Then      'Has a value
  55. '           reduce txtclass to characters only
  56.             temp = Left(cmbClass.Value, 1)
  57.             sSQL1 = sSQL1 & " AND ForecastMealsMaster.Class LIKE " & """* "
  58.             sSQL1 = sSQL1 & temp & " *"""
  59.         End If
  60.     End If
  61.  
  62. ' Add code for Flight
  63.     If Flight_set > 0 Then     'Has a value
  64.         cmbFlight.SetFocus
  65.         sSQL1 = sSQL1 & " AND ForecastMealsMaster.Flight LIKE " & """*"
  66.         sSQL1 = sSQL1 & cmbFlight.Value & "*"""
  67.     End If
  68.     sSQL = sSQL & sSQL1
  69.     Set qrytemp = db.CreateQueryDef("HistoryForecastPax", sSQL)
  70.  
  71.  
  72.      ' Add to HistoryForecastForm customer,flight and class
  73.     sSQL = "SELECT ForecastMealsMaster.Customer, ForecastMealsMaster.Flight,ForecastMealsMaster.Class,"
  74.     sSQL = sSQL & "ForecastMealsMaster.Flight_Date, ForecastMealsMaster.Aircraft_Type,"
  75.     sSQL = sSQL & "ForecastMealsMaster.Origin, ForecastMealsMaster.Destination,"
  76.     sSQL = sSQL & "ForecastMealsMaster.Forecast_Pax, ForecastMealsMaster.Actual_Pax,"
  77.     sSQL = sSQL & "ForecastMealsMaster.Fpax_ShortTerm, ForecastMealsMaster.Fpax_LongTerm,"
  78.     sSQL = sSQL & "ForecastMealsMaster.FConfig, ForecastMealsMaster.ActualConfig,"
  79.     sSQL = sSQL & "ForecastMealsMaster.LastWkAvgPax, ForecastMealsMaster.LyPax, ForecastMealsMaster.LastWkPax,"
  80.     sSQL = sSQL & "ForecastMealsMaster.Last2WkPax, ForecastMealsMaster.comment,"
  81.     sSQL = sSQL & "[Actual Pax Last update date].LastUpdateDate"
  82.     sSQL = sSQL & " FROM ForecastMealsMaster, [Actual Pax Last update date]"
  83.     sSQL = sSQL & " WHERE ((ForecastMealsMaster.Flight_Date) Between "
  84.     sSQL = sSQL & " NOW() AND NOW()+30 ) "
  85.     sSQL = sSQL & sSQL1
  86.     Set qrytemp = db.CreateQueryDef("UpdateForecastPax", sSQL)
  87.     UpdateForecastPax.Requery
  88. Exit_ReDoMenuList:
  89.   On Error Resume Next
  90.   Exit Sub
  91.  
  92. Err_ReDoMenuList:
  93.  
  94.  End Sub
Jan 9 '07 #1
6 3516
NeoPa
32,556 Expert Mod 16PB
Try :
FormID.SubFormControlName.Form.ReQuery
Where :
FormID is often Me. but can be a more fully referenced link to a form.
SubFormControlName is the name of the control on the form (SubForm type) which the SubForm is held in.
Form is simply the text 'Form'.
Let us know how this works for you.
Jan 9 '07 #2
Try :
FormID.SubFormControlName.Form.ReQuery
Where :
FormID is often Me. but can be a more fully referenced link to a form.
SubFormControlName is the name of the control on the form (SubForm type) which the SubForm is held in.
Form is simply the text 'Form'.
Let us know how this works for you.
I tried your format but while my code has changed the query correctly the subforms are not refreshing with the new query.
Is there a better way?
What I have is a main table and the query selectes a subset of the table based on date.
This query is what is used by the subform to list the data.
Then the users refine that subset, by selecting an individual flight and passenger class from separate combo boxes in the main form. These combo boxes are themselves subqueries of the main query the main form. Basically I am filtering the data, but avoiding Access's filters to simplify it for users.

This results in one row per day for the time period chosen. The subform displays 18 of the tables' fields in each row, and the user can then update 3 of these as appropriate.

The second subform is only history and is read only, but also records from the same table.

I've tried having the subform in datasheet mode but found I couldn't set the font size. However this also did not refresh. I have also tried the refresh method. Setting the focus also seems to no nothing. Access help seems to be of no help to me at all.

I would appreciate if you could point me to any better ways as I seem to be getting bogged down. Thank you for your time.
Chris
Jan 10 '07 #3
NeoPa
32,556 Expert Mod 16PB
I'm afraid I know of no better ways personally.
I would look at why this isn't working for you, rather than other ways to effect the same results.
There is almost certainly some (little) thing you've got wrong in your database. Find it, and the database will work in a logical way. If you try to go around it you will always have a kludge in your code.
That would be my advice.
Jan 10 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
I'm afraid I know of no better ways personally.
I would look at why this isn't working for you, rather than other ways to effect the same results.
There is almost certainly some (little) thing you've got wrong in your database. Find it, and the database will work in a logical way. If you try to go around it you will always have a kludge in your code.
That would be my advice.
Chris

The problem may lie in the two queries running off the same table. Can you post the sql of both queries and tell us which is the main and which the subform query.

Mary
Jan 10 '07 #5
Chris

The problem may lie in the two queries running off the same table. Can you post the sql of both queries and tell us which is the main and which the subform query.

Mary
Thanks Mary,
Based on your info I started again and have decided to teach users how to use Filters. I now have a working form.
Jan 24 '07 #6
MMcCarthy
14,534 Expert Mod 8TB
Thanks Mary,
Based on your info I started again and have decided to teach users how to use Filters. I now have a working form.
That's great Chris. Glad to hear the problems solved.
Jan 24 '07 #7

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

Similar topics

2
by: John Baker | last post by:
Hi: I have a Pop Up form that involves a main form and sub form. The sub form has the results of a query on the main form. I need to automatically perform exactly he same action that takes...
5
by: Andrew Chanter | last post by:
I have a situation where I am using an unbound dialog form to update data in an Access 2002 split back end / front end scenario. The data update is done via an ADO call (direct to the back end...
2
by: S. van Beek | last post by:
Dear reader, I have a strange situation. In a Form with a list box to search for a record in the form it self. The field in the list box is also available in the form. On an other...
2
by: Peter Oliphant | last post by:
I now have graphics being drawn in the Paint event of my form (yeah, and it's very cool). Problem was that it only updated any changes to these graphics when Paint was called. So, I then made it...
10
by: tasmisr | last post by:
This is an old problem,, but I never had it so bad like this before,, the events are refiring when clicking the Browser refresh button. In the Submit button in my webform, I capture the server side...
6
by: scott | last post by:
I guess this is a simple one but I can't seem to get it to work. I want to refresh an open form "onClose" of another. I have a Close button on a form which has User Details on it. If I update...
2
by: Robert | last post by:
I am trying to give the user dynamic search capabilities to select almost any record in the database from criteria they select. Everything seems to work except when I open the display form to...
12
by: martin1 | last post by:
All, is there window form refresh property? I try to set up window form refresh per minute. Thanks
5
by: tshad | last post by:
I have an interface I am using to get access to some of the objects on my form: a textbox (Status) and my statusbar (StatusBar). In my class, which is actually in another class from my form I have...
5
by: BlackBox | last post by:
I have a Listbox1 in the main form and I can add listbox1 items in the parent form. But when I close the parent form Listbox1 in the main form does not get refresh. I need to re-open the app. ...
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: 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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.