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

Requery Subform

How to requery the subform based on date range after update in Main form. Example: The forecast quantity in main form was revised based on the new startdate and enddate. How do I requery the subform in order to revise the forecast quantity?

Thanks for any help.
Elizabeth
Sep 23 '12 #1
16 20844
Seth Schrock
2,965 Expert 2GB
There are a couple of ways to initiate the requery code. You could setup an After_Update event on your enddate textbox or you could create a button that has the On_Click event set. Either way, you would use the following code (replace frmSubForm with the name of your subform):

Expand|Select|Wrap|Line Numbers
  1. Me.frmSubForm.Requery
Sep 23 '12 #2
Sorry for my late response, I was trying to work it out. I think I am not clear with my question.

The main form and subform are linked by a CodeName. The main form has a forecast quantity (Fcast) and startdate & enddate)for each CodeName. The quantity for each CodeName in the main form keeps changing at certain date range.
The subform has a quantity field and running dates
Using a command how to auto refresh the quantity field by date range in subform based on quantity changed in the main form. Example: during Jan 15 to 31, quantity in main form changed to 100
how to auto refresh the quantity in subform between Jan 15 to 31? Thank you in advance for your help. Regards EOL
Sep 26 '12 #3
TheSmileyCoder
2,322 Expert Mod 2GB
I have read it a couple of times, but I simply cannot make head or tails of it.

If the calculation is automatic(Calculated in query, or in the controlsource of the controls), you can simply do a requery as Seth has suggested.



If it is not automatic, then you need to define and explain the logic for us to have any chance of helping you.
Sep 26 '12 #4
Seth Schrock
2,965 Expert 2GB
That is what I understood from the first post. The only reason that I can think of that my solution wouldn't work would be that the subform is not a form embedded in the main form, but a separate form that you are calling a subform because of it dependence on the main form. If I am correct that the subform really is a subform control on the main form, what have you tried and what were the results?
Sep 26 '12 #5
Thanks for your immediate response. The subform is embedded in the main form. Main form fields: CodeID (unique for each product), Product Name, Production Daily Quantity, StartDate and EndDate.
The embedded subform is linked to the main form by CodeID, I have a command in the main form that initially populate the subform with production daily quantity and running date (from startdate to enddate). During production the Daily Quantity and Enddate on the main form changes. Example: On the main form Item1 original Production Daily Quantity is 100, startdate is June 1 and enddate is June 30. After auto populating the subform, the subform has following records:

Code ID RunningDate Production Daily Quantity
Item1 June 1 100
Item1 June 2 100
Item1 June 3 100
.....
Item1 June 15 100
Item1 June 16 100
Item1 June 17 100
.....so on till June 30

If the quantity on the main form is revised for Item1 to 200 from June 15 to June 30, the subform to auto refresh like below:

Item1 June 15 200
Item1 June 16 200
Item1 June 17 200
.....etc till June 30

How to code it that subform will auto refresh quantity based on date range.

Thanks & regards, EOL
Sep 26 '12 #6
Seth Schrock
2,965 Expert 2GB
The actual data doesn't matter for this particular question as we are looking at the subform as a whole and not just trying to update certain fields.

Back to my previous question, what have you tried and what were the results/error messages?
Sep 26 '12 #7
lyodmichael
75 64KB
can you show us your code?
Sep 26 '12 #8
My code can only filter within the date range I need, which is perfect but I don't know how to continue to write the code that will auto replace the quantity on subform based on the revised quantity entered on the main form. Thank you for your help. Regards EOL

Expand|Select|Wrap|Line Numbers
  1. Private Sub Image87_Click()
  2. With Me.subformname.Form
  3.     .Filter = "[DDate] BETWEEN " & Format(Me.LastOfRevSDate, "\#mm\/dd\/yyyy\#") & " AND " & Format(Me.LastOfRevEDate, "\#mm\/dd\/yyyy\#")
  4.     .FilterOn = True
  5. End With
  6. End Sub
Sep 30 '12 #9
Seth Schrock
2,965 Expert 2GB
Please use the <CODE/> button when posting code.

Ah, so what you want isn't a requery, but a replacing of a value (very different things). Now the question is, do you want to replace the quantity on the subform for all the records in the subform, or just the record that is selected?
Sep 30 '12 #10
Want to replace just the records selected in the subformm based on the revised quantity in the main form. Tank you and regards EOL
Oct 1 '12 #11
Seth Schrock
2,965 Expert 2GB
When you say Records, I'm assuming multiple records. How are you selecting the multiple records? Do you have checkboxes or are you just using the Ctrl or Shift buttons to select the ones that you want?
Oct 1 '12 #12
I filter the records based on date range using the above code.
Oct 2 '12 #13
Seth Schrock
2,965 Expert 2GB
You said, "Want to replace just the records selected in the subformm based on the revised quantity in the main form."

What method are you using to select the records in the subform? At this point, I don't need to know how the subform information is generated, but how are you selecting the individual records? A checkbox?
Oct 2 '12 #14
zmbd
5,501 Expert Mod 4TB
Seth, ElizabethLOng;
I've been following this for a little while now and now I'm wonder if we have a mis-communication.

EL:
When you say "replace" most people, in my experience, will tend to understand you to mean, that the item (record) is discarded and a new item is put in it's place... think changing the tires. If I replace the front driver-side tire, the old tire is sent to the rubish/recycle bin and a new tire from inventory is put into service.

If what you want is a new selection of the records... then the analogy might be along the lines of tire rotation in that one or two of the tires you see in the driver's side might trade sides with the passenger. You haven't replaced the tires, you have a different view.

::
We do need to understand the real structure underneath the database and the forms.
::

- What version of MS Access are you using?

- From what I understand, there are two related tables that are being used for the forms; is this correct?

- From what I understand, there are two forms, one form is based on one of the afore mentioned tables and the the second is bassed on the the other table; is this correct?
Oct 2 '12 #15
Sorry it took me sometime to reply, still trying to work out my code. I am using MS Access 2007. My code can filter records in the subform based on the date range entered in the main form. The problem with my code after filtering the subform it only refreshed the first record, is there a way to refresh all the filtered records? I need to constantly change the quantity at a certain date range in the subform based on the revised quantity in the mainform. Thanks for your help.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Image87_Click()
  2.     Dim strFilter As Variant
  3.     Dim strSDate As String
  4.     strSDate = Me.SDate
  5.     Dim strEDate As String
  6.     strEDate = Me.EDate
  7.  
  8.     'check sdate
  9.     If Not IsDate(Me.[SDate]) Or Not IsDate(Me.[EDate]) Then
  10.         MsgBox "Valid dates must be entered"
  11.         Exit Sub
  12.     End If
  13.     If Me.[EDate] < Me.[SDate] Then
  14.         MsgBox "End date must be later than start date"
  15.         Exit Sub
  16.     End If
  17.  
  18.     'if both sdate and edate are valid, run filter
  19.     strFilter = "[sfmDDate] BETWEEN " & Format(Me.SDate, "\#mm\/dd\/yyyy\#") & _
  20.                 " AND " & Format(Me.EDate, "\#mm\/dd\/yyyy\#")
  21.     Forms!FormName!SubformName.Form.Filter = strFilter
  22.     Forms!FormName!SubformName.Form.FilterOn = True
  23.     Forms!FormName!SubformName.Form!SubformControlName = Me!FormRevisedQTY.Value
  24.  
  25. ExitSub:
  26.  
  27. End Sub
  28.  
Oct 7 '12 #16
zmbd
5,501 Expert Mod 4TB
try inserting: Forms!FormName!SubformName.Form.Requery after line 23 of the posted code.

You'll also find the following insight article (and the refered to cascade) to be of interest: http://bytes.com/topic/access/insigh...filtering-form
... http://bytes.com/topic/access/insigh...mbo-list-boxes
and the overall map is at the bottom of this page "Microsoft Access / VBA Insights Sitemap" scroll down there... TONS and TONS of information!
Oct 7 '12 #17

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

Similar topics

0
by: Michelle | last post by:
Hi all I have a main form which has a combo box and a subform. The two forms are linked by ShiftPatternName which is basically the value in the combo. the combo has the following code ...
2
by: amywolfie | last post by:
I have read the other posts on this topic, but didn't find an answer specific to what I need. I have a main form: frmFeeInput, which contains 2 subforms: 1) sfrmFootnotes 2) sfrmLoanProducts ...
4
by: mooseshoes | last post by:
All: Form A: Main_Form Form B: Sub_Form (has the control name: Sub_Form_Control_Name) Form C: Independent_Form Form C is based on a table which is also used by Form B. When Form C is used...
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....
7
by: SBC News Groups | last post by:
I have a form that the user enters some information on and then clicks a button to save the record. I do with the following line: DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,...
1
by: Alessandro | last post by:
Io devo aggiornare i campi di una sottomaschera. Con una maschera normale uso il comando docmd.requery !! ma con una sottomaschera non so come scrivere il codice
3
by: LROCCO | last post by:
Hi, I have a form which contains a subform. When I'm entering data into the subform it seems to requery automatically. When this occurs the focus goes to the start of the subform. Firstly,...
2
by: bbatson | last post by:
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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:
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.