How to combine two vba code into one code

RonNCmale

New member
Local time
Today, 16:25
Joined
Mar 4, 2008
Messages
1
I need vba code to be able to print a single label and also to print on a label sheet that has missing labels. In other words to be able to move the label to a particular label on the label sheet.

I've found two VBA codes. one will print only the current label:

Private Sub cmdPrintLabel_Click()
'Send STGO data to label report
Dim str As String
On Error GoTo ErrHandler
If IsNull(Me!UnitNumber) Then
Exit Sub
End If
str = "UnitNumber = '" & Me!UnitNumber & "'"
Debug.Print str
Open report in Print Preview.
DoCmd.OpenReport "rptSTGOLabels", acViewPreview, , str
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " _
End Sub

the other code moves the labels the number entered to a unused area on the label sheet.

Private Sub cmdPrint_Click()
Dim rst As New ADODB.Recordset
Dim bytCounter As Byte
Dim bytBlanks As Byte
On Error GoTo ErrHandler
bytBlanks = Forms!frmLabels!txtBlanks.Value
On Error GoTo 0
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE FROM tblSTGOLabels"
Set rst.ActiveConnection = CurrentProject.Connection
rst.Open "SELECT * FROM tblSTGOLabels", , _
adOpenDynamic, adLockOptimistic
For bytCounter = 2 To bytBlanks
rst.AddNew
rst.Update
Next
rst.Close
Set rst = Nothing
DoCmd.RunSQL "INSERT INTO tblSTGOLabels " _
& "SELECT * FROM STGO"
DoCmd.SetWarnings True
DoCmd.OpenReport "rptSTGOLabels", acViewPreview
Exit Sub
ErrHandler:
MsgBox "Please enter a valid label number"
DoCmd.SetWarnings True
End Sub

If possible I need to combine these codes to be able to print a single label to a unused label on the label sheet. Any help will be appreaciated.
 
Simple Software Solutions

Use this link to get what you are looking for
[URL="http://support.microsoft.com/kb/299024/en-us"[/URL]
 

Users who are viewing this thread

Back
Top Bottom