Search code examples
vbams-access

Add text box at specific location in report base on value


I'm working on a cut list generator but I'm having difficulty on the final report. I'd like to display a rectangle that represents the factory length piece with lines indicating cut points. In each segment I'd like to have the length of the piece shown. Using Report.line I've created the rectangles needed but I'm not sure how to get text in each box. Here is a sample output so far Sample Output As an example I want the three rectangles for Piece #1 to have 48" in them, probably all the way to the left. Any suggestions? I thought createReportControl might work but I'm not sure that is the correct approach. I'm also thinking about one text box with a monospace font so I can scale the input across the entire width. Any suggestions are appreciated.

Thanks, Dave

I played around with the monospace font idea. It isn't as pretty as I would like but I'm getting closer.
enter image description here


Solution

  • The issue is that I cannot keep the text in the same spot in each box. There is one line lower on the page that pushes the number almost out the right side of the box.
    Sample Output

    This code is functional but I'm looking at the cosmetics. I'm inserting spaces between my values using the following function:

    Private Function InsertSpaces(CutLen, PieceLen) As String
        MaxChar = 50 ' 6 inch 14pt Courier text box 
        cutchar = Int(CutLen / PieceLen * MaxChar)
        Cutcharcount = Len(Str(CutLen))
        cutchar = cutchar - Cutcharcount + 1
        For i = 1 To cutchar
            InsertSpaces = InsertSpaces + " "
        Next
    End Function
    

    I'm just trying to clean it up. CreateReportControl was giving me a error because I wasn't in design mode. I'm guessing that is because it ran as part of OnFormat of the Detail section.