Home > Blockchain >  Printing a different value in a text box on multiple copies
Printing a different value in a text box on multiple copies

Time:08-02

I have a button that prints a form on the current record.

The form contains a combobox with something like: 123005TEST This combobox is a lookup to another textbox which is a combination of three text boxes(on a different form):

=([OrderNr] & ("" [Aantal]) & "" & [SapArtNr])

OrderNr is 12300 and Aantal is 5 and SapArtNr is TEST, creating: 123005TEST


My question is, when I click print, is it possible to print a certain amount of copies based on Aantal 5, so printing 5 copies.

And here comes the tricky part.

To have each printed copy a different value in the combobox, so the first copy would have this written in the combobox on the printed paper: 123001TEST and copy two would be 123002TEST and so on, until 5.

CodePudding user response:

I didn't understand which textbox will receive the sequential text. So I put a dummy in the example code:

Option Explicit

Private Sub cmdPrintIt_Click()
    Dim strOrderNr As String
    Dim strAantal As String
    Dim strSapArtNr As String
    Dim intHowManyCopies As Integer
    Dim intCopy As Integer
    Dim strToTextBox As String

    strOrderNr = Me.OrderNr.Text
    strAantal = Me.Aantal.Text
    strSapArtNr = Me.SapArtNr.Text

    On Error Resume Next
    intHowManyCopies = CInt(strAantal)
    On Error GoTo 0
    
    If intHowManyCopies <> 0 Then
        For intCopy = 1 To intHowManyCopies
            strToTextBox = strOrderNr & CStr(intCopy) & strSapArtNr
            Me.TheTextBoxToReceiveText.Text = strToTextBox
            'put your code to print here
        Next
Else
    MsgBox "Nothing to print! Check it."
End If
End Sub
  • Related