Need assistance
I am trying to add 3 zeros before the value. If the value is 1 it should convert to 0001 and 1000 should read as 1000
please guide me where am making a mistake.
NewFileName = NewFilePath & TransactionID.Value Format(TransactionID, "000") & " " & "CoID-" & PurCoId.Value & " NEXPPur-Att1" & Right(oldFileName, 4)
following is the the complete Event.
Private Sub AttachmentA_Click()
If IsNull(AttachmentA.Value) Or AttachmentA.Value = "" Then
Dim fDialog As Object
Dim oldFileName, OldFilePath, NewFileName, NewFilePath As String
Dim varFile As Variant
NewFilePath = "H:\2018-2019 Ledgers\Office Attachments 2018-2019\Lahore\NEXP LHE Purchase"
' Set up the File Dialog. '
Set fDialog = Application.FileDialog(3)
With fDialog
' Set the title of the dialog box. '
.Title = "Please select the image to attach"
' Clear out the current filters, and add our own.'
.Filters.Clear
.Filters.Add "JPEG Images", "*.JPG"
.Filters.Add "PNG Images", "*.PNG"
.Filters.Add "GIF Images", "*.GIF"
.Filters.Add "XLSX document", "*.xlsx"
.Filters.Add "DOCS document", "*.docx"
.Filters.Add "PDF document", "*.PDF"
.Filters.Add "All Files", "*.*"
.AllowMultiSelect = False
If .Show = -1 Then
oldFileName = .SelectedItems(1)
'NewFileName = NewFilePath & TransactionID.Value & " " & "CoID-" & PurCoId.Value & " NEXPPur-Att1" & Right(oldFileName, 4)
NewFileName = NewFilePath & TransactionID.Value Format(TransactionID, "000") & " " & "CoID-" & PurCoId.Value & " NEXPPur-Att1" & Right(oldFileName, 4)
FileCopy oldFileName, NewFileName
AttachmentA.Value = NewFileName
Else
MsgBox "File selection cancelled!"
End If
End With
Else
Application.FollowHyperlink AttachmentA.Value
End If
End Sub