UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
3 Pages V  1 2 3 >  (Go to first unread post)
   Reply to this topicStart new topic
> Allen Browns Multiple Forms Client Method, Access 2016    
 
   
JAchord
post Aug 20 2019, 09:51 AM
Post#1



Posts: 147
Joined: 11-July 14



Anybody know of a way to set the form filter when using Allen Browns multiple form client method. I can get it to work but it just opens a duplicate of the form I am currently viewing with the same filter. So basically two forms showing the same data. This isn't very useful in practice for me. Here is the module code I am using. As you can see I tried using global variables to set the form filter with. At least i started making the global variables but could not figure out how to use them. This is called with "=openclient()" directly in the on click field for the control. Maybe if I move it to VBA i can set the form filter but I am at a loss.

CODE
Public dupItemDataFRM As New Collection    'Instances of frmClient.
Function OpenAClient()
    'Purpose:    Open an independent instance of form frmClient.
    Dim frm As Form
    Dim Globalmasteritem As String
    Dim Globalchilditem As String
    

    'Open a new instance, show it, and set a caption.
    Set frm = New Form_ItemDatafrm
    frm.Visible = True
    'frm.Caption = "Item " & Me.item & " Data"

    'Append it to our collection.
    dupItemDataFRM.Add item:=frm, key:=CStr(frm.hwnd)

    Set frm = Nothing
End Function

Function CloseAllClients()
    'Purpose: Close all instances in the dupItemDataFRM collection.
    'Note: Leaves the copy opened directly from database window/nav pane.
    Dim lngKt As Long
    Dim lngI As Long

    lngKt = dupItemDataFRM.Count
    For lngI = 1 To lngKt
        dupItemDataFRM.Remove 1
    Next
End Function
Go to the top of the page
 
theDBguy
post Aug 20 2019, 10:03 AM
Post#2


UA Moderator
Posts: 76,791
Joined: 19-June 07
From: SunnySandyEggo


Hi. I may be going blind but I don't see where you're storing or assigning your filter for the form. Typically, you would use something like:
CODE
...
frm.Visible = True
frm.Filter = "PersonID=" & PersonID
frm.FilterOn = True
...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
GroverParkGeorge
post Aug 20 2019, 10:26 AM
Post#3


UA Admin
Posts: 36,164
Joined: 20-June 02
From: Newcastle, WA


Can you provide the link to the source for this code? (I know, Allen Browne, but a precise link would make it a lot handier to find the right one.)

However, theDBGuy's comment is probably what you need to incorporate.

--------------------
My Real Name Is George. Grover Park Consulting is where I did business for 20 years.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
JAchord
post Aug 20 2019, 10:33 AM
Post#4



Posts: 147
Joined: 11-July 14



I open the first form"itemDataFRM" from a dashboard and filter based on a combobox selection. Each form could be called from one of three different subforms.Here is an example of code from one subform to open the second form. Right now I use a second form "itemdataPopUpFRM" to view this information.

CODE
On Error GoTo Subitem_DblClick_Err

    If Not IsNull(Subitem) Then
        If CurrentProject.AllForms("itemdatapopupfrm").IsLoaded = False Then DoCmd.Close acForm, "itemdatapopupfrm" 'close form if open and reload to ensure that it will load new data
        DoCmd.OpenForm "Itemdatafrm", , , "[ItemIDKey]=" & Me.MatlItemIDKey.Value 'open form to new item
        DoCmd.Hourglass False
    Else
        DoCmd.OpenForm "Itemdatafrm", , , "[ItemIDKey]=" & Me.MatlItemIDKey.Value 'open form to new item
        DoCmd.Hourglass False
    End If


So you are saying that this might work.

This in the module
CODE
frm.Filter = "ItemIDKEY=" & GlobalchilditemIDKEY



Then replace the above VBA code with this

CODE
On Error GoTo Subitem_DblClick_Err

    If Not IsNull(Subitem) Then
        GlobalchilditemIDKEY = me.matlItemIDKEY.value

        Call openclient()

       GlobalchilditemIDKEY = nothing
   else
   end if

This post has been edited by JAchord: Aug 20 2019, 10:36 AM
Go to the top of the page
 
JAchord
post Aug 20 2019, 10:38 AM
Post#5



Posts: 147
Joined: 11-July 14



Here is the link http://allenbrowne.com/ser-35.html
Go to the top of the page
 
theDBguy
post Aug 20 2019, 10:41 AM
Post#6


UA Moderator
Posts: 76,791
Joined: 19-June 07
From: SunnySandyEggo


QUOTE (JAchord)
So you are saying that this might work.

This in the module
CODE
frm.Filter = "ItemIDKEY=" & GlobalchilditemIDKEY

Yes, try that but don't forget to add the FilterOn line as well and let us know how it goes.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
JAchord
post Aug 20 2019, 12:34 PM
Post#7



Posts: 147
Joined: 11-July 14



Well it kind of works but I get an error 3709 "the search key was not found in any record" It is highlighting the code that defines the filter. I think it is because the original form has a filter. Not sure how to remove the filter on the newform before it opens without removing the filter on the form that is already open. this is when I have the GlobalchilditemIDKEY as string. If I change it to GlobalchilditemIDKEY as integer or long then I just get a blank form with no data.
Go to the top of the page
 
theDBguy
post Aug 20 2019, 12:45 PM
Post#8


UA Moderator
Posts: 76,791
Joined: 19-June 07
From: SunnySandyEggo


Hi. I can't say for sure in your case, but that error message usually means there's something off with the data. For example, you can't search on a field with null or invalid data that otherwise has good data.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
JAchord
post Aug 20 2019, 03:26 PM
Post#9



Posts: 147
Joined: 11-July 14



it may be that the original idkey is a number and the filter for is an integer in that case. Not sure why it keeps coming up blank if i have the temp variable as an integer.
Go to the top of the page
 
ADezii
post Aug 20 2019, 03:36 PM
Post#10



Posts: 2,698
Joined: 4-February 07
From: USA, Florida, Delray Beach


Here is a Demo that I created that will hopefully point you in the right direction. It will create Multiple Form Instances, each based on an Employee selected from a Combo Box. Hope this helps. The Instances will be 'stacked' on top of one another.
This post has been edited by ADezii: Aug 20 2019, 03:37 PM
Attached File(s)
Attached File  Multiple_Form_Instances.zip ( 297.84K )Number of downloads: 9
 
Go to the top of the page
 
JAchord
post Aug 21 2019, 12:58 PM
Post#11



Posts: 147
Joined: 11-July 14



thanks that might work. i will see if I can get it working and let you know.
Go to the top of the page
 
JAchord
post Aug 21 2019, 03:43 PM
Post#12



Posts: 147
Joined: 11-July 14



Yours worked fine however when I tried it the way i am trying to use it there are issues. I butchered yours to more closely represent what I am trying to do. If you double click on the employee id in the subform it opens a new form but with no data populated.
Attached File(s)
Attached File  Modified_Multiple_Form_Instances.zip ( 313.82K )Number of downloads: 9
 
Go to the top of the page
 
ADezii
post Aug 22 2019, 08:49 AM
Post#13



Posts: 2,698
Joined: 4-February 07
From: USA, Florida, Delray Beach


Attached File  Multiple_Form_Instances_2.zip ( 295.68K )Number of downloads: 7
  1. You are declaring glblemployeeid in the Public Function fOpenNewInstance(), where it will be 'Local' to the Procedure in Scope. It is clear that your intentions are to make this Variable 'Global/Public' in Scope, in which case it must be Declared in the General Declarations Section of a Standard Code Module.
  2. You are assigning a Value to this Variable in the DblClick() Event of the [EmployeeID] Field, but it's Value will not be retained in fOpenNewInstance().
    CODE
    Private Sub EmployeeID_DblClick(Cancel As Integer)
    glblemployeeid = Me.EmployeeID.Value

    Call fOpenNewInstance          'Value of glblemployeeid will not persists in the Function
    End Sub
  3. Proper Declaration for glblemployeeid:
    CODE
    Option Compare Database
    Option Explicit
    'Author:    Allen J Browne, July 2004
    'Email:     allen@allenbrowne.com

    Public colInstance As New Collection  'Instances of frmInstance.
    Public glblemployeeid As Long
  4. Your Sub-Form is not Linked to the Main Form, so I set the Values of the Link Child/Master Properties to [EmployeeID] for illustration purposes (see attached Graphic).
  5. I hope that my explanations have not confused you, download the Attachment and look at the Revisions.

This post has been edited by ADezii: Aug 22 2019, 08:51 AM
Attached File(s)
Attached File  Multiple_Form_Instances_2.zip ( 295.68K )Number of downloads: 14
Attached File  Link.JPG ( 18.45K )Number of downloads: 0
 
Go to the top of the page
 
JAchord
post Aug 22 2019, 08:53 AM
Post#14



Posts: 147
Joined: 11-July 14



thanks ADezii I will give this a shot. Also thanks for your patience as i bumble through this. I saw someone else post with the same problem in a very old post but a solution was never posted. Not sure if that one was ever resolved. My subforms have links, just didn't do it here to have more results to see if the form was actually changing data or just duplicating.
This post has been edited by JAchord: Aug 22 2019, 08:54 AM
Go to the top of the page
 
JAchord
post Aug 22 2019, 10:01 AM
Post#15



Posts: 147
Joined: 11-July 14



Great this works perfect if the form is already open and I double click an item in the subform. However if i try to open the form from the dashboard. I get an error in my security module for the "with forms (frmname) line. This function is called at the load of every form. Basically just keeps the uninformed from editing or deleting data. It says the form can not be found I tried adding frmName=frm in the dasPublic module. No luck there. This is so close to working properly its frustrating. I can open the form using the original method seen below and then open new forms by double clicking a field in the sub-form but it replaces the original form.

CODE
Public Function mySetSec(frmName As String)
' frmName is the name of the form to be passed into this procedure at call time
Select Case (TempVars!strSecLvl)
   Case "Developer"
            Call ShowNavigationPane
            With Forms(frmName)
                '.DataEntry = False
                
                .AllowEdits = True
                .AllowDeletions = True
                .AllowAdditions = True
                .AllowFilters = True
            End With
        Case "Administrator" ' can filter, edit & add but not delete
            With Forms(frmName)
                '.DataEntry = False
                
                
                .AllowEdits = True
                .AllowDeletions = False
                .AllowAdditions = False
                .AllowFilters = True
            End With


Module is called from the dashboard with
CODE
On Error GoTo ViewItembtn_Click_Err
If IsNull(Me.Itemcbx.Value) Then
DoCmd.Hourglass False
MsgBox "This will not work unless you enter a value first!"

Else
    GlobalchilditemIDKEY = Me.Itemcbx.Column(3)
    Call OpenAClient
    'DoCmd.OpenForm "itemDatafrm", acNormal, "", "[ItemIDKey]=" & Me.Itemcbx.Column(3)
End If

ViewItembtn_Click_Exit:
    Exit Sub

ViewItembtn_Click_Err:
    DoCmd.Hourglass False
    MsgBox Error$
    Resume ViewItembtn_Click_Exit


Form open is
CODE
Private Sub Form_Open(Cancel As Integer)

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Sorry,No records found."
Cancel = True
End If
Call mySetSec(Me.Form.Name)
DoCmd.Hourglass False

End Sub


and dasPublic is
CODE
Public dupItemDataFRM As New Collection
Public GlobalchilditemIDKEY As Long  'Instances of frmClient.
Function OpenAClient()
    'Purpose:    Open an independent instance of form frmClient.
    Dim frm As Form
    Dim Globalmasteritem As String
    
    
    

    'Open a new instance, show it, and set a caption.
    Set frm = New Form_ItemDatafrm
    frmName = frm
    frm.Visible = True
    frm.RecordSource = "Select * From ItemBasicqry Where [ItemIDKey]= " & GlobalchilditemIDKEY
    

    'Append it to our collection.
    dupItemDataFRM.Add item:=frm, key:=CStr(frm.hwnd)
    
    Set frm = Nothing
End Function

Go to the top of the page
 
ADezii
post Aug 22 2019, 10:41 AM
Post#16



Posts: 2,698
Joined: 4-February 07
From: USA, Florida, Delray Beach


At this point, I would need to see the actual DB, stripped of any sensitive Data along with a detailed explanation of what is not working and where it is not working.
Go to the top of the page
 
JAchord
post Aug 22 2019, 11:52 AM
Post#17



Posts: 147
Joined: 11-July 14



Acctually it is working for some reason. If i open the first form like I always did and then double click the item in subform it works. Not shure what fixed it but thanks for all the help.
Go to the top of the page
 
JAchord
post Aug 23 2019, 01:50 PM
Post#18



Posts: 147
Joined: 11-July 14



One more question how would i reference these new forms. The original form is itemdataFRM in the code below. Anytime I try to update one of the subsequent forms with vba in the client It ends up updating the original form.

CODE
If CurrentProject.AllForms("itemdatafrm").IsLoaded Then
            If IsNull(Forms!itemdatafrm.SupercedeItemIDKey.Value) And Forms!itemdatafrm.Status.Value = 90 Then Forms!itemdatafrm.SupercedeItemIDKey.Value = Me.AlternateItemkeytbx.Value
            Else
            End If
Go to the top of the page
 
theDBguy
post Aug 23 2019, 01:54 PM
Post#19


UA Moderator
Posts: 76,791
Joined: 19-June 07
From: SunnySandyEggo


Hi. If I remember correctly, you would use the reference in the collection where you stored a pointer or ID for each instance of the form you opened.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
JAchord
post Aug 23 2019, 03:24 PM
Post#20



Posts: 147
Joined: 11-July 14



I guess I will work on it next week. This is killing all of my functions that looked back at that original form for a value. Solved one problem but caused quite a few more. I am guessing I need to do something with this line "dupItemDataFRM.Add item:=frm, key:=CStr(frm.hwnd)" but can not figure out how to code it into something usable. I guess the collection ID would be the item and key from this line. This would be a temporary variable. Could I make a temp value that is tempformname = "item" & "Key" then on the open or load event of the form frmname = tempformname. Then all of my controls that reference that form could be pointed at tempformname.
Go to the top of the page
 
3 Pages V  1 2 3 >


Custom Search


RSSSearch   Top   Lo-Fi    5th December 2019 - 04:47 PM