Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / April 2006

Tip: Looking for answers? Try searching our database.

Problem with linked forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dbnDavid - 27 Apr 2006 23:29 GMT
I used the wizard to link two forms by means of a command button
(cmdOpenSubs) on one form (frmAgents) that opens a second form
(frmSubclients) filtered to display the records that relate to a control
value on the currently displayed first form.

So when the value for the field (PrmClntID) in the relevant control on the
first form is the value for "Agent X", the second form opens filtered for
records with "Agent X".

This works, except that if I add new records in the filtered second form
then the form is no longer specific to the “Agent X” value. I get the
existing records for "Agent X", but if I enter a new records the filter falls
away and I have to re-enter the value for "Agent X" each time.

Same problem occurs if I use a form and subform, though linked forms are
more suitable here.

Here is the code the wizard generated for the command button. I know very
little about VBA, but would it be possible to tweak this code to get around
the problem?

Private Sub cmbOpenSubs_Click()
On Error GoTo Err_cmbOpenSubs_Click

   Dim stDocName As String
   Dim stLinkCriteria As String

   stDocName = "frmSubclients"
   
   stLinkCriteria = "[PrmClntID]=" & Me![txtPrmCntID]
   DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmbOpenSubs_Click:
   Exit Sub

Err_cmbOpenSubs_Click:
   MsgBox Err.Description
   Resume Exit_cmbOpenSubs_Click
   
End Sub
Duane Hookom - 28 Apr 2006 03:03 GMT
Using a form and subform with the Link Master/Child properties should always
default the foreign key field in the subform to the Primary key value on the
main form.

You can add to your code to set the default value of PrmClntID. I prefer to
send and use OpenArgs in the form but this method might work if you have a
control on frmSubclients named txtPrmClnID bound to PrmClntID.

Private Sub cmbOpenSubs_Click()
On Error GoTo Err_cmbOpenSubs_Click

   Dim stDocName As String
   Dim stLinkCriteria As String

   stDocName = "frmSubclients"

   stLinkCriteria = "[PrmClntID]=" & Me![txtPrmCntID]
   DoCmd.OpenForm stDocName, , , stLinkCriteria
   Forms!frmSubClients.txtPrmClnID.DefaultValue = Me![txtPrmCntID]
Exit_cmbOpenSubs_Click:
   Exit Sub

Err_cmbOpenSubs_Click:
   MsgBox Err.Description
   Resume Exit_cmbOpenSubs_Click

End Sub

>I used the wizard to link two forms by means of a command button
> (cmdOpenSubs) on one form (frmAgents) that opens a second form
[quoted text clipped - 38 lines]
>
> End Sub
dbnDavid - 28 Apr 2006 05:08 GMT
Thanks for the suggestion, but it hasn't worked. The only difference is that
when the second form opens from the command button I also get an error
message saying "Application-defined or object-defined error." I click on OK
on the error message and it goes away, then the second form opens and works
just as before. Still doesn't preserve the default value for the PK of the
first form for new records.

I'm afraid I don't know enough about VBA to follow your comment about
preferring to send and use OpenArgs on the form.
Duane Hookom - 28 Apr 2006 05:26 GMT
You would open the form with similar code:
Private Sub cmbOpenSubs_Click()
On Error GoTo Err_cmbOpenSubs_Click

   Dim stDocName As String
   Dim stLinkCriteria As String

   stDocName = "frmSubclients"

   stLinkCriteria = "[PrmClntID]=" & Me![txtPrmCntID]
   DoCmd.OpenForm stDocName, , , stLinkCriteria,,,Me!txtPrmCntID

Exit_cmbOpenSubs_Click:
   Exit Sub

Err_cmbOpenSubs_Click:
   MsgBox Err.Description
   Resume Exit_cmbOpenSubs_Click

End Sub

Then in frmSubclients, use code in the On Open like:

If Len(Me.OpenArg & "") >0 Then
   Me.txtPrmCntlID.DefaultValue = Me.OpenArgs
End If

Signature

Duane Hookom
MS Access MVP

> Thanks for the suggestion, but it hasn't worked. The only difference is
> that
[quoted text clipped - 8 lines]
> I'm afraid I don't know enough about VBA to follow your comment about
> preferring to send and use OpenArgs on the form.
dbnDavid - 28 Apr 2006 06:28 GMT
Your first bit of code is OK, but the second:

> Then in frmSubclients, use code in the On Open like:
>
> If Len(Me.OpenArg & "") >0 Then
>     Me.txtPrmCntlID.DefaultValue = Me.OpenArgs
> End If

doesn't work. The error message I get is
"Compile error: Method or data member not found" and ".OpenArg" is
highlighted in the vba window.
Duane Hookom - 28 Apr 2006 12:35 GMT
You didn't fix my typo ;-)

If Len(Me.OpenArgs & "") >0 Then
    Me.txtPrmCntlID.DefaultValue = Me.OpenArgs
End If

Signature

Duane Hookom
MS Access MVP

> Your first bit of code is OK, but the second:
>
[quoted text clipped - 7 lines]
> "Compile error: Method or data member not found" and ".OpenArg" is
> highlighted in the vba window.
dbnDavid - 28 Apr 2006 22:26 GMT
Thanks very much Duane.

Looking long and hard at your code (I'm on a steep learning curve here) I
did eventually figure that there might be a typo so I tried fixing it, only
to find that the debug then picked up other things (so at least I knew I'd
got it right fixing your typo!). I gave up for a while, then came back and
discovered, looking really hard at the screen, that I was introducing new
typos of my own. And now at last it's all working just as it should. So
that's good, and the extremely useful little lesson in coding made it a
double bonus!

> You didn't fix my typo ;-)
>
[quoted text clipped - 13 lines]
> > "Compile error: Method or data member not found" and ".OpenArg" is
> > highlighted in the vba window.
Duane Hookom - 29 Apr 2006 05:47 GMT
Glad to hear you got it working and learned about code.
Signature

Duane Hookom
MS Access MVP

> Thanks very much Duane.
>
[quoted text clipped - 25 lines]
>> > "Compile error: Method or data member not found" and ".OpenArg" is
>> > highlighted in the vba window.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.