?
Solved

SubForm Link criteria when using form visible true or false

Posted on 2013-12-07
6
Medium Priority
?
600 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 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