Solved

SubForm Link criteria when using form visible true or false

Posted on 2013-12-07
6
589 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

831 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