Results 1 to 6 of 6
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    formatting issue

    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

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    I think you need more 0's.

    Code:
    Format(TransactionID, "0000")

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also, this line
    Code:
    Dim oldFileName, OldFilePath, NewFileName, NewFilePath As String
    doesn't do what you think. (unless you want "oldFileName", "OldFilePath" & "NewFileName" Variants)
    "oldFileName", "OldFilePath" & "NewFileName" are defaulting to Variants and only "NewFilePath" is being declared as a String.

    In VBA, you must explicitly declare variable types.
    You can use
    Code:
    Dim oldFileName As String, OldFilePath As String, NewFileName As String, NewFilePath As String
    or
    Code:
    Dim oldFileName As String
    Dim OldFilePath As String
    Dim NewFileName As String
    Dim NewFilePath As String

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Dang! While I was composing in NotePad for a copy/paste dump, someone beat me to the punch again. That's OK, as it was only a jab. Here comes a round-house punch

    Pullleeez put lengthy code samples within code tags with nice indentation. Not sure I see the need for all those filters if you're going to end with *.* anyway.
    Last points:
    - .Value is the default property of most form data controls, so you don't need to employ it.
    - I'm not a big fan of declaring variables inside an IF block. Setting, OK; declaring no. To each their own, I guess.

    Code:
    Private Sub AttachmentA_Click()
    Dim fDialog As Object
    Dim oldFileName As String, OldFilePath As String
    Dim NewFileName As String, NewFilePath As String
    Dim varFile As Variant
    
    If IsNull(AttachmentA) Or AttachmentA = "" Then
      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 "All Files", "*.*"
       .AllowMultiSelect = False
       If .Show = -1 Then 
         oldFileName = .SelectedItems(1)
         'NewFileName = NewFilePath & TransactionID & " " & "CoID-" & PurCoId & " NEXPPur-Att1" & Right(oldFileName, 4)
         NewFileName = NewFilePath & TransactionID Format(TransactionID, "000") & " " & "CoID-" & PurCoId & " NEXPPur-Att1" & Right(oldFileName, 4)
         FileCopy oldFileName, NewFileName
         AttachmentA = NewFileName
       Else
         MsgBox "File selection cancelled!"
         Exit Sub '<< code may attempt to follow hyperlink when no file was selected. Then again, maybe not but I would Exit to be sure
       End If
      End With
    
    Else
      Application.FollowHyperlink AttachmentA
    End If
    
    End Sub
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    Going back to your question...
    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)
    It's my understanding that when you format a number as your doing, the 0's represent place holders. So 000 would be a 3 digit number
    Format(12,"000") would be 012.
    Format(12,"0000") would be 0012.
    Format(12,"000000") would be 000012.
    Format(30412,"000000") would be 030412.

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    True, everything up to 99 would be prefaced with a zero. After that, no.
    Can also use 000#, as in format (50,"000#")
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form Formatting Issue
    By Allienne in forum Forms
    Replies: 3
    Last Post: 12-13-2018, 11:17 AM
  2. Formatting Issue
    By JohnnyDarkside in forum Access
    Replies: 2
    Last Post: 08-01-2017, 11:37 AM
  3. Issue with Report Formatting
    By Nashskye13 in forum Reports
    Replies: 6
    Last Post: 10-26-2012, 04:20 PM
  4. Conditional Formatting Issue
    By RachelBedi in forum Access
    Replies: 1
    Last Post: 10-19-2012, 05:34 PM
  5. Formatting Issue
    By mkc80 in forum Access
    Replies: 1
    Last Post: 08-26-2012, 11:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums