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

Linking DE form and subform to same record in same table

4
Very new to VBA and struggling to link the main form and the subform to the same record in the same table. Currently they are each entering separate records in the same table.

They are linked by the date in the parent-child connection and both contain a date textbox, the only difference is that the main allows the user to enter the date and the date is invisible on the subform.

I have tried a few pieces of code that I have found on similar boards across the internet but none seem to work for me. I feel like part of the problem is that I don't know where exactly I should put it - ie. onentry, beforeupdate, etc.

As some further background to this problem, the purpose of having linked record form and subform entries to the same table is that the subform pops up based on selection on the main form to allow further entry if needed. I don't want to make it a tab because I'm trying to poka yoke this process to prevent addition entry where it is not needed.
Nov 6 '17 #1

✓ answered by NeoPa

A1M6K:
I have done that and set both of those fields that you mentioned to Date.
Let me correct you on terminology here. I think I understand what you mean but terminology - its use and misuse - can be a perennial source of problems so getting it right can prove particularly important. The two items that needed setting were properties of the SubForm control. If you have date fields you should certainly try, where possible, to give them a name other than 'Date', which is, of course, a reserved word. You can use Reserved Words a field names, but it's not generally recommended due to the likelihood of misunderstanding being introduced.

A1M6K:
Alternatively, is there a way to have fields on a form become visible based on a previous selection (such as my check box)? This would eliminate the need for a subform while serving the same purpose.
Absolutely. This is quite a common requirement. The example below illustrates the approach. I have a table about people with one Field called Nationality and another called VisaExpiry. On my form I only want to show the latter if the Nationality value =/= 'British'. So I have two controls (cboNationality & txtVisaExpiry) on the form to reflect these Field values - one of which should only show when the Nationality value is anything other than British.

We need to make sure the visibility is set under two circumstances.
  1. When we change from showing one record to another.
  2. When the value within a single record is changed.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Call SetVUVisibility
  3. End Sub
  4.  
  5. Private Sub cboNationality_AfterUpdate()
  6.     Call SetVUVisibility
  7. End Sub
  8.  
  9. Private Sub SetVUVisibility()
  10.     With Me
  11.         .txtVisaExpiry.Visible = (.cboNationality <> "British")
  12.     End With
  13. End Sub
NB. As a general rule we don't allow members to set their own posts as Best Answer. Under special circumstances we may allow it, but this isn't really one of those I'm afraid.

6 3058
NeoPa
32,556 Expert Mod 16PB
Are you using the term subform as in Access's SubForm, or do you mean something else. Access SubForms don't pop up. They are a part of the main Form they're attached to.
Nov 6 '17 #2
A1M6K
4
It is an Access Subform, it is part of the main but I have made it invisible and also made it open when the user selects 'Yes' on a check box. My apologies for the confusion, that is what I meant when I said it pops up.
Nov 6 '17 #3
NeoPa
32,556 Expert Mod 16PB
Interesting concept. Linking a main and a sub form together is usually done by setting the Link Master Fields and Link Child Fields properties on the SubForm control itself (NOT the sub form but the SubForm/SubReport control on the main form which contains the sub form - if that makes sense).

Linking to the same record may be a problem. You may find that one of them locks out the other and you can get in a mess if you're not very careful.
Nov 7 '17 #4
A1M6K
4
Thanks NeoPa.

So to be sure I understand you correctly, accessing the subform from where it is situated on the main as opposed to opening it separately and accessing the individual properties? If that is what you mean, I have done that and set both of those fields that you mentioned to Date.

Although it might be on the messier side I'm determined to make it happen one way or another. Alternatively, is there a way to have fields on a form become visible based on a previous selection (such as my check box)? This would eliminate the need for a subform while serving the same purpose.
Nov 7 '17 #5
A1M6K
4
Hello All,

I seem to have cracked the code (haha) after trying a few different combinations of things from various posts. For those who are looking through this thread for a similar answer, here are the various combinations that I am using that seem to work so far.

Please note that I switched to using ID as the parent-child connection and just made it invisible on both form and subform. I also use a checkbox to open the subform instead of making it visible on the main all the time.

In the main form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ID_AfterUpdate()
  2.  
  3.     Me.Form.AllowAdditions = False
  4.     DoCmd.Requery "FrmEntryHelp1"
  5.  
  6. End Sub
  7. ------------------------------------------------
  8. Private Sub Help_still_required__Click()
  9.  
  10.     If True Then
  11.         If Me.Dirty = True Then Me.Dirty = False
  12.         DoCmd.Save acForm, "FrmEntry"
  13.         DoCmd.OpenForm "FrmEntryHelp1", , , "ID=" & Me!ID
  14.     End If
  15.  
  16. End Sub
In the subform:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnHelpRequest_Click()
  2.     If CheckForEmpty = False Then
  3.         MsgBox "Please fill in empty fields."
  4.     Else
  5.         DoCmd.Close acForm, "FrmEntry"
  6.         DoCmd.Save acForm, "FrmEntryHelp1"
  7.         DoCmd.Close acForm, "FrmEntryHelp1"
  8.     End If
  9.     Form_FrmTrackerMain.Requery
  10.     Form_FrmTrackerMain.Refresh
  11.  
  12. End Sub
I believe the fact that I close the main (FrmEntry) then save and then close the sub (FrmEntryHelp1) has made quite a difference. Again, this is a combination of solutions from different threads that all suddenly came together to work after trying SEVERAL different combinations. Hopefully this will work for someone else too!
Nov 7 '17 #6
NeoPa
32,556 Expert Mod 16PB
A1M6K:
I have done that and set both of those fields that you mentioned to Date.
Let me correct you on terminology here. I think I understand what you mean but terminology - its use and misuse - can be a perennial source of problems so getting it right can prove particularly important. The two items that needed setting were properties of the SubForm control. If you have date fields you should certainly try, where possible, to give them a name other than 'Date', which is, of course, a reserved word. You can use Reserved Words a field names, but it's not generally recommended due to the likelihood of misunderstanding being introduced.

A1M6K:
Alternatively, is there a way to have fields on a form become visible based on a previous selection (such as my check box)? This would eliminate the need for a subform while serving the same purpose.
Absolutely. This is quite a common requirement. The example below illustrates the approach. I have a table about people with one Field called Nationality and another called VisaExpiry. On my form I only want to show the latter if the Nationality value =/= 'British'. So I have two controls (cboNationality & txtVisaExpiry) on the form to reflect these Field values - one of which should only show when the Nationality value is anything other than British.

We need to make sure the visibility is set under two circumstances.
  1. When we change from showing one record to another.
  2. When the value within a single record is changed.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Call SetVUVisibility
  3. End Sub
  4.  
  5. Private Sub cboNationality_AfterUpdate()
  6.     Call SetVUVisibility
  7. End Sub
  8.  
  9. Private Sub SetVUVisibility()
  10.     With Me
  11.         .txtVisaExpiry.Visible = (.cboNationality <> "British")
  12.     End With
  13. End Sub
NB. As a general rule we don't allow members to set their own posts as Best Answer. Under special circumstances we may allow it, but this isn't really one of those I'm afraid.
Nov 12 '17 #7

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

Similar topics

0
by: Jim Moseby | last post by:
I stumbled across this while trying to update a table with a timestamp type column. At the time, I didn't know that the timstamp column would update itself when a row was changed. A kind gentleman...
6
by: JackT | last post by:
I want to get a column count several times in one query using different filters but can't work out how to do it - can anyone point me in the right direction? For example, how would combine these...
1
by: Richard | last post by:
Thats a mouthfull of a title what I'm after should be really simple. I have a form with a subform which itself has a subform the final subform contains an individuals record. The individuals...
4
by: Jim M | last post by:
Two questions: 1) I have a scheduling application (Access 2002) that allows multiple staff members to edit notes on their meetings and appointments from their offices. A receptionist views a...
10
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some...
1
by: thabit | last post by:
Good times for all Is there any way to link form-subform with more than 3 fields, since the wizard (subform field linker) does not support more than 3 fields linking
11
by: banderson | last post by:
Hello, I know I've seen an answer to this question before, but I cannot seem to find it again. After searching for a few hours, I've decided to re-post in hopes someone can give advice and/or send...
1
by: Guru S | last post by:
I haev a table "emp_details" with two fields ID,Name. and created a form "record" with text boxs adn a command button. I want to get the information from the user in these two text boxes and when...
2
by: Gerald Taylor | last post by:
Please excuse any idiotic questions as Access/VBA is a new area to me. I have inherited an Access Database/Application that is used to sign in and out visitors and Staff to our community Centre....
15
by: glennyboy | last post by:
good day. sample database: table1 col1 col2 col3 A item1 100 A item2 200
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: 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
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
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.