Results 1 to 9 of 9
  1. #1
    kacocal is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2015
    Posts
    26

    Generate List of -Detail screen < 13 inches

    Hi MS Access Experts,



    Could someone help me to use VBA to find the all the forms which has names contain "-detail" that have form width less than 13 inches.

    e.g. The display should be like:

    Form name Form Width
    ------------- -------------
    A-detail 10
    B-detail-xx 12
    C-detail 9

    Many thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    try:

    Code:
    Public Sub scanAllForms()
    Dim f As Form
    Dim vTwips
    Dim o As Object
    Const kTwipsPerInch = 1440
    
    
    vTwips = 14 * kTwipsPerInch
    
    For Each o In Application.CurrentProject.AllForms
        
        DoCmd.OpenForm o.Name, acDesign
        Set f = Forms(0)   'assumes no other forms are open when this runs
        If f.Width < vTwips Then
          Debug.Print f.Name
        End If
    
    
       DoCmd.Close acForm, f.Name
    Next
    Set o = Nothing
    Set f = Nothing
    End Sub
    instead of debug.print to get the list, you can use sql to append it to a table.

  3. #3
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Well the first bit is easy - to get all the form names in a query;
    Code:
    SELECT MSysObjects.Name, MSysObjects.Type, MSysObjects.Flags, MSysObjects.ForeignName, *FROM MSysObjects
    WHERE (((MSysObjects.Type)=-32768)) and [Name] Like "*-detail*"
    Then you need to get a bit clever - I'm not sure you can get the forms width without it being open... (happy to be proved wrong just haven't had time to investigate)
    So you will need to open the form in design view, (to prevent any code running) check the property then close it.

    Code:
    Option Compare Database
    Option Explicit
    
    
    Sub GetFormWidths()
    
    
        Dim rs As Recordset
        Dim sSql As String
        Dim iWidth As Long  ' the width will be reported in twips - I'll let you work that out in inches.
        Dim sForm As String
        
        ' open a recordset with the form names - change the criteria appropriately
        sSql = "SELECT MSysObjects.Name, MSysObjects.Type, MSysObjects.Flags, MSysObjects.ForeignName"
        sSql = sSql & " FROM MSysObjects WHERE (((MSysObjects.Type) = -32768)) and [Name] Like " *-Detail* ""
    
    
        Set rs = CurrentDb.OpenRecordset(sSql, dbOpenSnapshot)
        
        rs.MoveFirst
    
    
        While Not rs.EOF Or rs.BOF
            
            sForm = (rs.Fields("name"))
            DoCmd.OpenForm sForm, acDesign, , , acFormPropertySettings, acHidden
            iWidth = Forms(sForm).Width
            DoCmd.Close acForm, sForm
            Debug.Print rs.Fields("name"), iWidth
            rs.MoveNext
        Wend
    End Sub
    This will list all the forms and their widths in twips, in the immediate window - hopefully you can work out the rest?
    Example from the immediate window of a small sample database;
    Code:
     GetFormWidth
    sfrmDetailLookUp              13656 
    sfrmFullDetails              13164 
    sfrmRepairList               13296
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    kacocal is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    26
    Hi Minty,

    Thank you for your reply. I am new to MS Access and I want to test your code. It doesn't have any button. Where can I enter the code and how can I run it?

    Thanks.

  5. #5
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    A number of ways - create a new code module and enter code in the VBA editor (Press Alt and F11 to get the editor window open)

    When prompted to save the Module call it modBasicFunctions or similar. (Don't call it GetFormWidths access will break!)

    In the VBA editor open the immediate window. (Press Ctrl+G to bring it up)
    Then simply type
    GetFormWidths and hit enter.

    Learn this technique for debugging it's invaluable. Also for learning functions.
    In the immediate window use ? to print a response, if you type the following and hit return

    ? CDbl(Now())

    You should get s0mething like
    43727.4002314815

    Which is the current date and time value as access actually stores it.

    You could then make a form, add a button and in the on click event simply use
    GetFormWidths to get the reulst in the immediate window.
    Finally you could change the results from a Debug.Print and add them to a string and print them out in a message box, or populate a list box with them etc. but we might be getting ahead of ourselves there.
    Last edited by Minty; 09-19-2019 at 06:38 AM.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,428
    ? CLng(Now())

    You should get s0mething like
    43727.4002314815
    think that should be CDbl to show the time element

  7. #7
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Ooops - I changed it when I tried it then forgot to update the poste - Thanks - fixed!
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    kacocal is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2015
    Posts
    26
    Thank you for all your help. The solutions worked just fine. Many thanks.

  9. #9
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Glad you got it working!
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-28-2018, 05:04 PM
  2. Replies: 3
    Last Post: 11-12-2013, 02:57 PM
  3. List Box Items Are De-Selected On A Screen Refresh
    By plengeb in forum Programming
    Replies: 2
    Last Post: 10-03-2012, 11:58 AM
  4. Access Report: List Detail Horizontally
    By rad1182 in forum Access
    Replies: 1
    Last Post: 01-11-2012, 04:24 PM
  5. Replies: 0
    Last Post: 12-23-2008, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums