How to place text boxes on a report according to co-ordinates from a table.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tasawer
    New Member
    • Aug 2009
    • 106

    #1

    How to place text boxes on a report according to co-ordinates from a table.

    Hi,

    I am trying to place several textboxes on a report with their absolute positions pre-defined and stored as numbers in a table, but I am having trouble acheving this.

    recordsource of a report has the expected values.

    on the report I have a textbox, 'txtCustCompany '
    in the onprint event code, I have:
    Code:
    txtCustCompany.Left=me.CustcompanyLeft
    txtcustCompany=me.CustCompany
    But first line of code throws an error.
    I am not sure which way to head.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. Let's assume that you have a Table named tblCoordinates with the following Fields:
      1. Control
      2. Left
      3. Top
      4. Width
      5. Height
    2. Copy-N-Paste the following Code into the Format() Event of the Detail Section to precisely position a Control named txtCustCompany:
      Code:
      Dim strControlName As String
      Dim lngLeft As Long
      Dim lngTop As Long
      Dim lngWidth As Long
      Dim lngHeight As Long
      
      strControlName = "txtCustCompany"
      
      lngLeft = DLookup("[Left]", "tblCoordinates", "[Control] = '" & strControlName & "'")
      lngTop = DLookup("[Top]", "tblCoordinates", "[Control] = '" & strControlName & "'")
      lngWidth = DLookup("[Width]", "tblCoordinates", "[Control] = '" & strControlName & "'")
      lngHeight = DLookup("[Height]", "tblCoordinates", "[Control] = '" & strControlName & "'")
      
      Me![txtCustCompany].Move Left:=lngLeft, Top:=lngTop, Width:=lngWidth, Height:=lngHeight

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      As an afterthought
      Code:
      Dim rst As DAO.Recordset
      Dim strControlName As String
      
      strControlName = "txtCustCompany"
      
      Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblCoordinates WHERE [Control] = '" & _
                                         strControlName & "';", dbOpenSnapshot)
        
      Me![txtCustCompany].Move Left:=rst!Left, Top:=rst!Top, Width:=rst!Width, Height:=rst!Height
      
      rst.Close
      Set rst = Nothing

      Comment

      • tasawer
        New Member
        • Aug 2009
        • 106

        #4
        Thanks for this. Definatly the sort of solution I was looking for.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          You are quite welcome.

          Comment

          Working...