473,378 Members | 1,321 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.

Updating table record from within filtered subform

33
Subform "SubPT" is bound to table TBL_TRAINING_PROTOCOL. The main form that contains it is unbound, and contains 3 unbound combo boxes: "ComboStudy", "ComboNumber", and "ComboVersion". Each of these sets the value of a locked text box in the subform, as you can see in the after_update code below. These text boxes are bound to the appropriate columns in TBL_TRAINING_PROTOCOL.

SubPT is filtered per the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. If IsNull(Me.ComboVersion) Then
  3.    Me.SubPT.Form.Filter = "[PROTOCOL TRAINING ID] = 0"
  4.    Me.SubPT.Form.FilterOn = True
  5.    End If
  6. End Sub
  7.  
  8. Private Sub ComboVersion_AfterUpdate()
  9. Forms!FRM_TRAINING_PROTOCOL!SubPT.Form!STUDY = Me.ComboStudy.Value
  10. Forms!FRM_TRAINING_PROTOCOL!SubPT.Form![PROTOCOL NUMBER] = Me.ComboNumber.Value
  11. Forms!FRM_TRAINING_PROTOCOL!SubPT.Form![PROTOCOL VERSION] = Me.ComboVersion.Value
  12. Me.SubPT.Form.Filter = "[PROTOCOL VERSION] = """ & Me.ComboVersion.Value & """"
  13. SubPT.Requery
  14. End Sub
Everything almost works out fine with the filtering: the correct records display, as does the starred new record row; but an additional, blank record also displays, and TBL_TRAINING_PROTOCOL has a new row with the 3 columns filled in per the text boxes.

My question is this: how do I tweak this so that only the currently extant records fitting the filter display, while also allowing me to add a new record which will include the values from the textboxes?

Thanks!
Dec 21 '15 #1

✓ answered by abcrf

Thanks for engaging me on this, Z. I managed to figure out how to get the intended result, which was actually pretty simple in the end.

Changed the above after_update code to:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboVersion_AfterUpdate()
  2. Me.SubPT.Form.Filter = "[PROTOCOL VERSION] = """ & Me.ComboVersion.Value & """"
  3. Forms!FRM_TRAINING_PROTOCOL!SubPT!SubStudy.DefaultValue = Chr(34) & Me.ComboStudy.Value & Chr(34)
  4. Forms!FRM_TRAINING_PROTOCOL!SubPT!SubNumber.DefaultValue = Chr(34) & Me.ComboNumber.Value & Chr(34)
  5. Forms!FRM_TRAINING_PROTOCOL!SubPT!SubVersion.DefaultValue = Chr(34) & Me.ComboVersion.Value & Chr(34)
  6. SubPT.Requery
  7. End Sub

7 1568
zmbd
5,501 Expert Mod 4TB
When you first open the form, no entries etc... does the form display correctly, that is, only the filtered records and the new-record row?
Dec 22 '15 #2
abcrf
33
Well, per the Form_Load code above, I have it set to initially only display records with a key value of 0, i.e. no records. It shows a single blank record, but doesn't make any sort of entry in the table.
Dec 22 '15 #3
zmbd
5,501 Expert Mod 4TB
In and of itself that is useful information.

For troubleshooting, would you mind setting the key value to 1 or something other current value in your recordset( :) ) just to see what is going on...

As for the data entry, I'm not expecting one to be made from the code you've provided thus-far. In the after_update event, I am actually not expecting a new record from the code in post one, there's nothing there to create a new record, the current record might be effected; however, this really depends on the form design and any other code you might have in the parent/child.
Dec 22 '15 #4
abcrf
33
Setting it to filter by key value = 20 instead of = 0 by default causes it to display entry 20, which can be modified (changes reflected in source table), and a starred new entry slot below it.
Dec 22 '15 #5
zmbd
5,501 Expert Mod 4TB
Just noticed, in the OP, On_Load line 3 [PROTOCOL TRAINING ID] vs after_update line 12 [PROTOCOL VERSION], did you intend to change the referenced field for the filter?
Dec 22 '15 #6
abcrf
33
Yeah. In general, I want to filter based on where the protocol version = the value they just set in ComboVersion. But when there's nothing in ComboVersion, I'm filtering based on the training id field (autonumber key) = 0, which I know will always return no results.
Dec 22 '15 #7
abcrf
33
Thanks for engaging me on this, Z. I managed to figure out how to get the intended result, which was actually pretty simple in the end.

Changed the above after_update code to:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboVersion_AfterUpdate()
  2. Me.SubPT.Form.Filter = "[PROTOCOL VERSION] = """ & Me.ComboVersion.Value & """"
  3. Forms!FRM_TRAINING_PROTOCOL!SubPT!SubStudy.DefaultValue = Chr(34) & Me.ComboStudy.Value & Chr(34)
  4. Forms!FRM_TRAINING_PROTOCOL!SubPT!SubNumber.DefaultValue = Chr(34) & Me.ComboNumber.Value & Chr(34)
  5. Forms!FRM_TRAINING_PROTOCOL!SubPT!SubVersion.DefaultValue = Chr(34) & Me.ComboVersion.Value & Chr(34)
  6. SubPT.Requery
  7. End Sub
Dec 22 '15 #8

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

Similar topics

1
by: entellisys | last post by:
Hi there, Does anyone know the simplest way I can trap the next record event in Access 2000 on a subform? I have a main form with tab control which holds several subforms, and the subforms...
4
by: YFS DBA | last post by:
How do I use VBA to insert a *new* record into a subform? I have a master form with client information, and a sub form with billing information. I want to click on a button ("Add Data") and have...
3
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
0
by: Alienz | last post by:
hiya! I wanted to make a multiple selection drop down list and I found the easiest way to do this was by creating a subform linked to a table with 2 values, the 1st value links to the main form...
4
by: | last post by:
This is blowing my mind because I thought this setup was working.... How is a new record generated in the table of a Child subform whenever a new record is generated in the table of the Master...
2
by: brenda.stow | last post by:
error msg " An error occured while referencing the object. You tried to run a visual basic procedure that improperly references a property or method of an object" This msg occurs everytime I add a...
2
by: ken | last post by:
I have the following code but it does not work correctly. DoCmd.GoToRecord , , acGoTo, MySubForm.Form.CurrentRecord When the code executes it does not bring me to the correct record. If...
1
by: stuart | last post by:
I have a list of records in a subform that a user can either edit or delete. This is an unbound form. If the user deletes a record, I want to refresh the form, and then position the cursor on the...
5
by: bplantes | last post by:
I have a "Dashboard" in a tool I am building which has a list of different buttons. Clicking on each button will display different subforms which show up in a window to the right of the menu. One...
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
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: 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...
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
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...

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.