none
Change control properties on a form RRS feed

  • Question

  • Hi all,

    I am trying to change some properties of text boxes on a form before a form is loaded.

    I need to switch between Single View and Continues View, depending if the user is adding or maintaining codes.

    I am using the below code from a standard sub:

        DoCmd.OpenForm "Frm_StockSerialNumbers", acDesign, , , , acNormal
        Forms("Frm_StockSerialNumbers").DefaultView = 0
        Forms("Frm_StockSerialNumbers").SStockCode_Label.Width = 4.339: Forms("Frm_StockSerialNumbers").SStockCode.Width = 6.445
        Forms("Frm_StockSerialNumbers").SStockCode_Label.Top = 0.603: Forms("Frm_StockSerialNumbers").SStockCode.Top = 0.603
        Forms("Frm_StockSerialNumbers").SStockCode_Label.Left = 0.603: Forms("Frm_StockSerialNumbers").SStockCode.Left = 5.101
        Forms("Frm_StockSerialNumbers").SStockCode_Label.Height = 0.582: Forms("Frm_StockSerialNumbers").SStockCode.Height = 0.582
        DoCmd.Close acForm, "Frm_StockSerialNumbers"
    

    After the above routine has run, I open the form for processing, BUT:

    The issue is that all the controls seemed to have "Disappeared" from the form. The controls are still there, but the Widths, Top, Left and Height values has been set to 0.0002, putting all the controls on top of each other, and not according to my code above.

    Any assistance on what I am doing wrong, will be appreciated.

    Thanks

    Deon

    Monday, September 9, 2019 11:54 AM

Answers

  • Access VBA uses twips as unit. 1 inch = 1440 twips / 1 cm = 567 twips

    If you specify in inches:

    Forms("Frm_StockSerialNumbers").SStockCode_Label.Width = 1440 * 4.339

    etc.

    If you specify in centimeters:

    Forms("Frm_StockSerialNumbers").SStockCode_Label.Width = 567 * 4.339


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Deon SA Monday, September 9, 2019 1:07 PM
    Monday, September 9, 2019 12:04 PM

All replies

  • Access VBA uses twips as unit. 1 inch = 1440 twips / 1 cm = 567 twips

    If you specify in inches:

    Forms("Frm_StockSerialNumbers").SStockCode_Label.Width = 1440 * 4.339

    etc.

    If you specify in centimeters:

    Forms("Frm_StockSerialNumbers").SStockCode_Label.Width = 567 * 4.339


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Deon SA Monday, September 9, 2019 1:07 PM
    Monday, September 9, 2019 12:04 PM
  • Thanks Hans - perfect!!
    Monday, September 9, 2019 1:07 PM