ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,726
- Office Version
- 2007
- Platform
- Windows
Hi,,
I have a userform with TextBox1 & TextBox 2 & CommandButton1
The code in use is shown below.
I open the userform & TextBox 2 is populated from another worksheet.
The value entered is always 6 characters & will never be the same ,example 1A2B3C etc etc
I type the customers name in TextBox1,example JAMES BOND
I then run the CommandButton1 code.
If i go the the folder where the pdf is saved i see the following file for that customer.
JAMES BOND 1A2B3C.pdf
The above is fine & works well.
This is where i need some additional code.
A previous Customer makes another purchase,example JAMES BOND
The value this time is 8A6S22
The saved file this time is as follows.
JAMES BOND 8A6522.pdf
Im thinking that the additional code should look for the customers name only & if present add 2 after his name, if two files for the same customer is present then add 3 etc etc
So example if 1 instance is there.
JAMES BOND 2 "THEN THE CODE"
If 2 files are there then.
JAMES BOND 3 "THEN THE CODE"
If the code to be used struggles to look at customers name only & not the code maybe use something like this JAMES BOND 2 *1A2B3C*
The code then only looks at the characters BEFORE the * "Make Sense"
Many Thanks
I have a userform with TextBox1 & TextBox 2 & CommandButton1
The code in use is shown below.
I open the userform & TextBox 2 is populated from another worksheet.
The value entered is always 6 characters & will never be the same ,example 1A2B3C etc etc
I type the customers name in TextBox1,example JAMES BOND
I then run the CommandButton1 code.
If i go the the folder where the pdf is saved i see the following file for that customer.
JAMES BOND 1A2B3C.pdf
The above is fine & works well.
This is where i need some additional code.
A previous Customer makes another purchase,example JAMES BOND
The value this time is 8A6S22
The saved file this time is as follows.
JAMES BOND 8A6522.pdf
Im thinking that the additional code should look for the customers name only & if present add 2 after his name, if two files for the same customer is present then add 3 etc etc
So example if 1 instance is there.
JAMES BOND 2 "THEN THE CODE"
If 2 files are there then.
JAMES BOND 3 "THEN THE CODE"
If the code to be used struggles to look at customers name only & not the code maybe use something like this JAMES BOND 2 *1A2B3C*
The code then only looks at the characters BEFORE the * "Make Sense"
Many Thanks
Rich (BB code):
Private Sub CommandButton1_Click()
Dim sPath As String
Dim strFileName As String
With ThisWorkbook.Worksheets("PRINT LABELS")
.Range("B3") = Me.TextBox1.Text ' ENTERS CUSTOMERS NAME TO WORKSHEET
.Range("A3") = Me.TextBox2.Text ' ENTERS PCB NUMBER TO WORKSHEET
End With
Unload PrinterForm
With ActiveSheet
If .Range("AB1") = "" Then
MsgBox "NO CODE SHOWN TO GENERATE PDF", vbCritical, "NO CODE ON SHEET TO CREATE PDF"
Exit Sub
End If
strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\" & .Range("B3").Value & " " & .Range("A3").Value & ".pdf"
.Range("A1:K23").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
MsgBox "PDF HAS NOW BEEN GENERATED", vbInformation + vbOKOnly, "GENERATE PDF FILE MESSAGE"
End With
sPath = "C:\Users\Ian\Desktop\REMOTES ETC\DISCO II CODE\DISCO II PDF\"
strFileName = sPath & Range("B3").Value & " " & Range("A3").Value & ".pdf"
If Dir(strFileName) <> vbNullString Then
ActiveWorkbook.FollowHyperlink strFileName
End If
End Sub