[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SubForm Link criteria when using form visible true or false

Posted on 2013-12-07
6
Medium Priority
?
595 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

649 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