Solved

SubForm Link criteria when using form visible true or false

Posted on 2013-12-07
6
592 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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