Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Mar 2005
    Location
    Leicestershire, United Kingdom
    Posts
    506
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi, I have the code below, which creates a text file with the extension 'blm'. However when it actually creates it, it calls it a BL11 file. If I change the M to a Q, so a BLQ file extension, it then calls it a BL4 extension file.

    Dim strFileName As String
    Dim strfilelocation As String
    Dim strQueryCount As Variant
    Dim strGeneratedDate As String

    strGeneratedDate = Format(Now, "dd-mm-yyyy hh:mm")
    strendstring = ".BLM"
    strgenerateddate2 = Format(Now, "dd-mm-yyyy-hh-mm" & strendstring)
    strFileName = strgenerateddate2
    strfilelocation = "\\Server\Database\Rightmove\"
    strfile = strfilelocation & strFileName
    strfile2 = strfilelocation & "qryRightmovefeed.txt"
    strfile3 = strfilelocation & "end.txt"
    strQueryCount = DCount("*", "qryRightmoveFeed")

    DoCmd.SetWarnings False
    'oCmd.TransferText acExportDelim, "Inventory_Specs", "M_Inventory", "Inventory.csv"
    DoCmd.TransferText acExportDelim, "QryRightmoveFeedExportSpecification", "qryRightmovefeed", "\\Server\Database\Rightmove\qryrightmovefeed. txt"
    DoCmd.SetWarnings True

    Close #1

    Open strfile For Output As #1
    ' Close before reopening in another mode.

    Print #1, "#HEADER#"
    Print #1, "Version : 3"
    Print #1, "EOF : '^'"
    Print #1, "EOR : '~'"
    Print #1, "Property Count : " & strQueryCount
    Print #1, "Generated Date : " & strGeneratedDate
    Print #1, ' Print blank line to file.

    Print #1, "#DEFINITION#"
    Print #1, "agent_ref^Address_1^Address_2^Address_3^Address_4 ^Town^Postcode1^Postcode2^Feature1^Feature2^Featur e3^Feature4^Feature5^Feature6^Feature7^Feature8^Fe ature9^Feature10^Summary^Description^Branch_ID^STA TUS_ID^BEDROOMS^PRICE^Price_Qualifier^Prop_Sub_ID^ Create_Date^Update_Date^Display_Address^Published_ Flag^Let_Date_Available^Let_Bond^Let_Type_ID^Let_F urn_ID^Let_Rent_Frequency^tenure_type_id^Trans_Typ e_ID^New_home_flag^Media_Image_00^Media_Image_01^M edia_Image_02^Media_Image_03^Media_Image_04^Media_ Image_05^Media_Image_06^Media_Image_07^Media_Image _08^Media_Image_09^media_image_60^media_image_text _60^media_image_61^media_image_text_61^media_docum ent_01^media_document_50^media_document_text_50^~"
    Print #1, ' Print blank line to file.

    Print #1, "#DATA#"

    Close #1

    Close #2

    Open strfile3 For Output As #2
    ' Close before reopening in another mode.

    Print #2,
    Print #2, "#END#"
    Print #2,

    Close #2

    Dim SourceNum As Integer
    Dim DestNum As Integer
    Dim Temp As String

    ' If an error occurs, close the files and end the macro.
    On Error GoTo ErrHandler

    ' Open the destination text file.
    DestNum = FreeFile()
    Open strfile For Append As DestNum

    ' Open the source text file.
    SourceNum = FreeFile()
    Open strfile2 For Input As SourceNum

    ' Include the following line if the first line of the source
    ' file is a header row that you do now want to append to the
    ' destination file:
    ' Line Input #SourceNum, Temp

    ' Read each line of the source file and append it to the
    ' destination file.
    Do While Not EOF(SourceNum)
    Line Input #SourceNum, Temp
    Print #DestNum, Temp
    Loop

    CloseFiles:

    ' Close the destination file and the source file.
    Close #DestNum
    Close #SourceNum

    ' Open the destination text file.
    DestNum = FreeFile()
    Open strfile For Append As DestNum

    ' Open the source text file.
    SourceNum = FreeFile()
    Open strfile3 For Input As SourceNum

    ' Include the following line if the first line of the source
    ' file is a header row that you do now want to append to the
    ' destination file:
    ' Line Input #SourceNum, Temp

    ' Read each line of the source file and append it to the
    ' destination file.
    Do While Not EOF(SourceNum)
    Line Input #SourceNum, Temp
    Print #DestNum, Temp
    Loop

    ' Close the destination file and the source file.
    Close #DestNum
    Close #SourceNu
    Exit Sub

    ErrHandler:
    msgbox "Error # " & Err & ": " & Error(Err)
    Resume CloseFiles
    Best Regards,

    Luke

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    So what is the question? Does the file actually get created with the correct extension?

    If windows find a file extension it does not know, it just calls the file a "blm" file etc. It does not know that it is really a text file.
    Regards
    John



  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The line

    strgenerateddate2 = Format(Now, "dd-mm-yyyy-hh-mm" & strendstring)

    should be

    strgenerateddate2 = Format(Now, "dd-mm-yyyy-hh-mm") & strendstring

    Your version included .BLM in the format string, and M got converted to the month number = 11 for November!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •