Solved

SubForm Link criteria when using form visible true or false

Posted on 2013-12-07
6
587 Views
Last Modified: 2013-12-11
Can I use a version of the following when simply making a subform visible or invisible rather than opening and closing. I'm trying to keep invisible subform synchronized with main and have the link field in subform populated when I add a new record to the main form

    Dim stLinkCriteria As String
    stLinkCriteria = "[ItemNumber]=" & Me![ItemNumber]
    DoCmd.OpenForm "MoreDetails", , , stLinkCriteria
0
Comment
Question by:DatabaseDek
  • 3
  • 3
6 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39703463
You use the filter criteria:


    Dim stLinkCriteria As String
    stLinkCriteria = "[ItemNumber]=" & Me![ItemNumber]
    Me.YourSubformControlName.Form.Filter = stLinkCriteria
    Me.YourSubformControlName.Form.FilterOn = True

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 39703480
Is this 'subform' a popup or a true subform embedded in the main form?  If it is an embedded subform, then you can synchronize the sub and main form by including the Item Number in the master/child  links.
0
 

Author Comment

by:DatabaseDek
ID: 39704136
Thank you

I have a linked field in the sub/mainform

It's a true subform.  As with all subforms I find that the most frustrating thing is that when moving to a new record the subform link field is not made until the main form has been saved or edited first. So you can get this ridiculous situation where the user moves to a new record and immediately tries to enter information in the visible subform Causing a "cannot update" error. So I make the subform invisible until data is added and saved to the main form.

So now when I click the make subform visible button on a main form that has not been saved I would be forced to give message "enter information on the main form first". To overcome this When the user clicks the make subform visible button I have to save the main form and then code

If IsNull(subform linked field)=true  then
subform linked field= Mainform Linked field.
end if

That's why I asked is there something like the code for on open. I can see how the form filter code will work but does it overcome the problem of a new record as above?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:DatabaseDek
ID: 39704140
Thank you

I have a linked field in the sub/mainform

It's a true subform.  As with all subforms I find that the most frustrating thing is that when moving to a new record the subform link field is not made until the main form has been saved or edited first. So you can get this ridiculous situation where the user moves to a new record and immediately tries to enter information in the visible subform Causing a "cannot update" error. So I make the subform invisible until data is added and saved to the main form.

So now when I click the make subform visible button on a main form that has not been saved I would be forced to give message "enter information on the main form first". To overcome this When the user clicks the make subform visible button I have to save the main form and then code

If IsNull(subform linked field)=true  then
subform linked field= Mainform Linked field.
end if

That's why I asked is there something like the code for on open. I can see how the form filter code will work but does it overcome the problem of a new record as above?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39704218
Ahh... I understand what you're asking now.

The users really *should* enter something in the main record before moving to the subform, and there should be certain required field(s) needed to start a mainform record.  This approach allows Access to do what it should do (prevent orphaned records, while automatically creating the linked ID *at appropriate times*)

 A good way to handle this is to leave the subform visible, but to add code to the Enter Event of the subform control (this is in the main form's design):

If me.newrecord = false then exit sub
If Me.SomeRequiredField & "" = "" then
    ' If the required field is empty then force the focus out of the subform with a user friendly message
    MsgBox "You need to enter data in field xyz before creating related records"
    Me.SomRequiredField.SetFocus
Else
   Me.Refresh     '<---- saves the data, and allows the user to enter subform data.
                           ' At this point, the subform link will automatically be created
End if

Open in new window

0
 

Author Closing Comment

by:DatabaseDek
ID: 39711977
Many thanks!!

Derek
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now