OPening more than one occurrence of a form (1 Viewer)

ryetee

Registered User.
Local time
Today, 08:40
Joined
Jul 30, 2013
Messages
952
Apologies to all that contributed here and thanks to you all!
I got a working version using the Allen Browne approach (thank you Allen).

I have one small problem. I now want to pass a parameter to the form that I'm opening so I added an extra line to what I had and have now got
Set frm = New Form_ListSales

frm.Visible = True
frm.Caption = frmName & " " & frm.Hwnd & ", opened " & Now()
frm.OpenArgs = StrOpenArgs

I thought this was work but I'm getting an error stating that frm.openargs is readonly. So how do I pass a parameter over to the each new form in the collection?
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 08:40
Joined
Sep 21, 2011
Messages
14,232
You pass the OpenArgs parameter(s) when you open the form.?
In the form you then test the passed parameter(s) and process them as you wish.

Check out the OpenForm statement.

As you are not using OpenForm, I would have thought there was no need for the OpenArgs?

HTH
 

ryetee

Registered User.
Local time
Today, 08:40
Joined
Jul 30, 2013
Messages
952
Can you post your database?

I'm not sure I can really as it has client data in so I'd have to spend a lot of time getting rid of sensitive stuff. And also it's in development and I'm ashamed of some of the ways I've done stuff (I ma getting that changed eventually!).

If it comes to that's the only way I can progress this then I'll have to make some time but at the moment I've far too much on elsewhere.

Sorry

I'll give it 10 mins see what I can come up with.
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:40
Joined
Sep 21, 2011
Messages
14,232
I have a feeling that you would need to create custom properties for the form?, but that is beyond me I'm afraid.:eek:
 

ryetee

Registered User.
Local time
Today, 08:40
Joined
Jul 30, 2013
Messages
952
I have a cut down version but have to head for home now. How do I upload it?
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:40
Joined
Sep 21, 2011
Messages
14,232
Go Advanced/Attach Files/Manage Attachments
 

sonic8

AWF VIP
Local time
Today, 09:40
Joined
Oct 27, 2015
Messages
998
I have a feeling that you would need to create custom properties for the form?, but that is beyond me I'm afraid.:eek:
That's what I would have suggested. It's actually pretty easy.


In the form:
Code:
Public Property Let MyProperty(newValue As Variant)
    ' Now do something with the data in newValue
    MsgBox "newValue ist: " & newValue
End Property


In the calling code:
Code:
Set frm = New Form_ListSales
    frm.MyProperty = StrOpenArgs
However, this property will only be set after opening the form is complete. So, other than OpenArgs it is not available during the Load- and Open-Event.
 

ryetee

Registered User.
Local time
Today, 08:40
Joined
Jul 30, 2013
Messages
952
OK So here it is.
I've pared it down somewhat to demonstrate what I'm after. I have my own ribbon. If you click on sales then on the left there are 4 "buttons" called Depositos, Albaran, Factura, and Pedido. These work none of the others should. Click on any and you'll be asked for a user and password - only 1 user admin, only 1 password "a".
They all ultimately open the customer form but from the ribbon they open ListSalesxxxxxx where xxxxxx Depositos, Albaran, Factura, or Pedido to pick up a paramater to pass to the customer form so that the right data can be displayed. If you then double click on Cust X it takes you to ListSales form which disguises for either the Depositos, Albaran, Factura, or the Pedido form. I wanted to pass a parameter to be picked up in openargs but I can't see how to do it. In the end I've put it in a public variable for the time being. This is probably ok for this but I want to be able to double click on rows displayed in the ListSales form so it would be useful to use the form collection and also open args.
Hope this is clear.
 

Attachments

  • formcollection.accdb
    1.1 MB · Views: 55

ryetee

Registered User.
Local time
Today, 08:40
Joined
Jul 30, 2013
Messages
952
That's what I would have suggested. It's actually pretty easy.


In the form:
Code:
Public Property Let MyProperty(newValue As Variant)
    ' Now do something with the data in newValue
    MsgBox "newValue ist: " & newValue
End Property


In the calling code:
Code:
Set frm = New Form_ListSales
    frm.MyProperty = StrOpenArgs
However, this property will only be set after opening the form is complete. So, other than OpenArgs it is not available during the Load- and Open-Event.

that works thanks. where does this code get run. ie is it before or after the load event, before or after the open event etc etc
 

sonic8

AWF VIP
Local time
Today, 09:40
Joined
Oct 27, 2015
Messages
998
that works thanks. where does this code get run. ie is it before or after the load event, before or after the open event etc etc
The sequence of events when opening a form is:
Open
Load
Resize
Activate
Current

The property will only be set after all these are completed.
 

ryetee

Registered User.
Local time
Today, 08:40
Joined
Jul 30, 2013
Messages
952
The sequence of events when opening a form is:
Open
Load
Resize
Activate
Current

The property will only be set after all these are completed.

One further question for you if you don't mind. When you use openform you can also pass over a where condition and a filter. With the collection where I'm using set frm =newXXXXX etc how would you achieve this?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:40
Joined
May 21, 2018
Messages
8,525
Using form instances you cannot open them dialog. So need to pass in anything. Just set the properties from the calling code after they are opened.
 

ryetee

Registered User.
Local time
Today, 08:40
Joined
Jul 30, 2013
Messages
952
Using form instances you cannot open them dialog. So need to pass in anything. Just set the properties from the calling code after they are opened.

OK I want the data presented on the to be driven by 2 fields from the calling form. I was hoping to pass over a where condition (to the query) so how can I do this now. By the time I set the properties hasn't the form already been loaded? If not how do I set the properties?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:40
Joined
May 21, 2018
Messages
8,525
Also since you have to explicitly make the form visible you can do all your manipulation before making it visible.
 

ryetee

Registered User.
Local time
Today, 08:40
Joined
Jul 30, 2013
Messages
952
Also since you have to explicitly make the form visible you can do all your manipulation before making it visible.


OK That makes sense. Still not clear how I cut down the rows on my query though.

If I was just using a 'normal' form I'd code something like

DoCmd.OpenForm "formname", acNormal, , "salesid = " & me.salesidforquery

I'm at a loss to know how to handle that with a collection. I don't see frm.where or anything that looks the thing I should be using!!
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:40
Joined
May 21, 2018
Messages
8,525
You can pass in a filter and all other properties.

dim frm as Form_SomeForm
set frm = new Form_SomeForm
with Frm
.filter = "salesid = " & me.salesidforquery
.filterOn = true
.OrderBy = SomeField
.backColor = someColor
...... whatever you want to set
end with
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:40
Joined
May 21, 2018
Messages
8,525
"Pass In" was a bad term. Should have said you can set the properties once you create the instance, because creating the instance also opens the form.
 

ryetee

Registered User.
Local time
Today, 08:40
Joined
Jul 30, 2013
Messages
952
You can pass in a filter and all other properties.

dim frm as Form_SomeForm
set frm = new Form_SomeForm
with Frm
.filter = "salesid = " & me.salesidforquery
.filterOn = true
.OrderBy = SomeField
.backColor = someColor
...... whatever you want to set
end with

Really appreciate this. You've expanded my depth of knowledge!
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:40
Joined
May 21, 2018
Messages
8,525
There are 3 ways I can think of to limit the records. Use a filter, change the recordsource query, or you could even set the recordset.

Code:
dim rs as dao.recordset
set rs = currentdb.openrecordset ("SELECT * from somequery WHERE SalesID = " & me.salesIDforQuery, dbopendynaset)

With Frm

  'query method
  .rowsource = "SELECT * from somequery WHERE SalesID = " & me.salesIDforQuery
  
  'Filter method
  .filter = "salesid = " & me.salesidforquery
  .filterOn = true
  
  'Recordset Method
  Set .recordset = RS
end with
Filter is probably the easiest, and that is actually what you are doing when using the docmd.openform and applying a criteria.
 

Users who are viewing this thread

Top Bottom