rename multiple instances of forms

toumack

Registered User.
Local time
Today, 15:15
Joined
May 14, 2011
Messages
13
Hi everyone,
I have the code to create multiple instances of a form, maximum of 12. I would like these 12 forms to be temporary rename so I can use the "DoCmd.MoveSize" command to show each one of them to a particular place on the screen. When the user is done, delete the forms. So the name I want for these form could be as simple as Form1 to Form12. Please take note that not all of the form is created, it could be any number to a maximum of 12.

Here is the code:
Code:
Function StackCompanyForms()

   Const conSQL = "SELECT * FROM Companies Order By Company"

    Dim dbs As DAO.Database, rst As DAO.Recordset
    Dim n As Integer

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset(conSQL)
    Dim i As Integer
    
    Do While Not rst.EOF
       n = n + 1
       
       Set frm = New Form_frmCompanies
       colPopups.Add frm, frm.hwnd & n
       frm.Caption = rst.Fields("Company")
       frm.Filter = "CompanyID = " & rst.Fields("CompanyID")
       frm.FilterOn = True
       frm.Visible = True
       DoCmd.MoveSize n * 360, n * 360
       rst.MoveNext
    Loop

End Function
 
Hi. Not sure why you need the name of the form. Have you tried using a reference to the instance? For example:
Code:
frm.Move n * 360, n * 360
Just a thought...
 
You Cannot name the instance. The name is a shared property of the class and each instance shares the same name. That is why you use a collection to manage your instances. Use the form move method on the form instance, not the docmd method.
 
Thanks dbGuy, yes I did and the only thing that does is that the first form move and all the others are on top of each others, I also tried a few other, here an image
I put the database on my one drive, here is the link,
The original database made by Ken Sheridan is accessible on the frmMenu to fit my needs I have created a few form and codes, to access mine this is on the frmMenuEnCours

Thanks for your help
 

Attachments

  • Effects of change in frm.move.jpg
    Effects of change in frm.move.jpg
    111.5 KB · Views: 173
Code:
Function StackCompanyForms()
   Dim wdth As Long
   Dim hght As Long
   Dim rowCounter As Integer
   Dim colCounter As Integer
   Const twipstoin = 1440
   
   Const conSQL = "SELECT * FROM Companies Order By Company"

    Dim dbs As DAO.Database, rst As DAO.Recordset
    Dim n As Integer

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset(conSQL)
    Dim i As Integer
    Do While Not rst.EOF
       n = n + 1
       
       Set frm = New Form_frmCompanies
       hght = frm.WindowHeight
       wdth = frm.Width
       colPopups.Add frm, frm.hwnd & n
       frm.Caption = rst.Fields("Company")
       frm.Filter = "CompanyID = " & rst.Fields("CompanyID")
       frm.FilterOn = True
       frm.Visible = True
       frm.Move colCounter * (wdth + (0.6 * twipstoin)), hght * rowCounter
       colCounter = colCounter + 1
       If n Mod 3 = 0 Then
         rowCounter = rowCounter + 1
         colCounter = 0
       End If
       rst.MoveNext
    Loop

End Function

attachment.php
 

Attachments

  • multi.jpg
    multi.jpg
    90.5 KB · Views: 255
Last edited:
Bingo, thanks MajP for your time, I will play with it because the form frmMenu I did maximize it, so I would like the first row to open from about 1/2 inch from the top, I can put 1 more in a row so 12 forms total.

Thanks again
 
This version was pretty basic. The idea could be expanded to actually determine screen size then resize the forms as needed to fit. I hard coded the number of columns, but this could be calculated. The basics are there in determining heights and widths and when to start a new row.
 
Perfect, this is because of people like you that its easier to improve our program.
Thanks again

attachment.php
[/QUOTE]
 

Users who are viewing this thread

Back
Top Bottom