Everything seems to work fine with code except printing, it is printing multiple copies of the form instead of a single.
Not sure what is going on here, any help would be greatly appreciated.
Not sure what is going on here, any help would be greatly appreciated.
Code:
Private Sub EnterPrint_cmd_Click()
Dim iRow As Long
Dim ws As Worksheet, txtSamp As Variant
Set ws = Worksheets("SampleLog")
Dim ts As Date
ts = Now
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for Person
If Trim(Me.txtPerson.Value) = "" Then
Me.txtPerson.SetFocus
MsgBox "Please enter Person"
Exit Sub
End If
'check for a Sample Id
If Trim(Me.txtSample1.Value) = "" Then
Me.txtSample1.SetFocus
MsgBox "Please enter a Sample Id"
Exit Sub
End If
'Create array for textboxes
txtSamp = Array(txtSample1, txtSample2, txtSample3, txtSample4, txtSample5, txtSample6, txtSample7, _
txtSample8, txtSample9, txtSample10, txtSample11, txtSample12, txtSample13, txtSample14)
For i = 0 To 13
If txtSamp(i).Value <> "" Then 'Test each tb for value
ws.Cells(iRow + i, 1) = txtSamp(i) 'Post value
End If
Next
For j = 0 To 13
If ws.Cells(iRow + j, 1) <> "" Then 'Test if value entered in range col A
ws.Cells(iRow + j, 2) = ts 'Date/time stamp
End If
'Fill Form
Range("Form!G6").Value = ts
Range("Form!D30").Value = ts
Range("Form!I6").Value = txtPerson
Range("Form!C9").Value = txtSample1
Range("Form!C10").Value = txtSample2
Range("Form!C11").Value = txtSample3
Range("Form!C12").Value = txtSample4
Range("Form!C13").Value = txtSample5
Range("Form!C14").Value = txtSample6
Range("Form!C15").Value = txtSample7
Range("Form!C16").Value = txtSample8
Range("Form!C17").Value = txtSample9
Range("Form!C18").Value = txtSample10
Range("Form!C19").Value = txtSample11
Range("Form!C20").Value = txtSample12
Range("Form!C21").Value = txtSample13
Range("Form!C22").Value = txtSample14
'Print Form
ScreenUpdating = False
Sheets("Form").Visible = True
Sheets("Form").Select
ActiveSheet.PrintOut
'Clear Form
Sheets("Form").Select
Range("I6,G6,C9:C28,D30:E30").Select
Selection.ClearContents
Sheets("Form").Visible = False
ScreenUpdating = True
Next
For k = 0 To 13 'Clean up
txtSamp(k).Value = ""
Next
txtPerson.Value = ""
txtPerson.SetFocus
ActiveWorkbook.Save
End Sub