Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Dannat is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Jan 2012
    Posts
    18

    Switchboard button to open txt file


    I was wondering if sum1 can point me to the coding needed to get the windows browse and import txt file by clicking on a button within a switchboard. I have a table that is formatted to the correct layout but every txt file is different name so I need the user the ability to select the file that is needed to append to an existing table.

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Go to this link: http://www.ammara.com/access_image_f...en_dialog.html
    click on Download Code
    create a new module and insert that code to open the browse window.

    The next step is DoCmd.TransferText

  3. #3
    Dannat is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Jan 2012
    Posts
    18
    I am trying but it doesn't seem to work. I have the following code in a button event and the table name I want to imprt the txt file to is called register:

    Private Sub btnOpen_Click()
    Dim strFilter As String
    Dim strInputFileName As String
    strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.txt")
    strInputFileName = ahtCommonFileOpenSave( _
    Filter:=strFilter, _
    OpenFile:=True, _
    DialogTitle:="Choose a text file...", _
    Flags:=ahtOFN_HIDEREADONLY)
    If Len(strInputFileName) > 0 Then
    DoCmd.TransferText (acImportDelim, "", "register", "", "", "", vbYes)
    Else
    'No file chosen, or user canceled
    End If
    End Sub

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Try this:

    Dim strFilter As String, strDir As String, strTitle As String, FileName As String, lngFlags As Long
    strFilter = "Text Files (*.txt)"
    strDir = "C:\"
    strTitle = "Open a file"
    FileName = ahtCommonFileOpenSave(InitialDir:=strDir, Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, DialogTitle:=strTitle)
    Debug.Print FileName

  5. #5
    Dannat is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Jan 2012
    Posts
    18
    Where do I place this code? I have been at this for 3 days now reading and reading so I am sorry if I seem rushed. I am under a deadline at work and it has been 8 years since I worked on a database.

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    This is the OnClick for the button. I am assuming that the downloaded code exists. Do a compile after you have entered this.

    No problem - I understand deadlines!

  7. #7
    Dannat is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Jan 2012
    Posts
    18
    I am able to get the open screen and with the coding you gave doesn't give me errors anymore but nothing is imported. it just basically closes the open file screen and nothing else happens.

  8. #8
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What do you want to happen? All the code above does is get the file name - you must then put the code in to do what you want with the file,e.g. Docmd.TransferText ....

  9. #9
    Dannat is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Jan 2012
    Posts
    18
    I have a text file generated everyday with a different name so I need the user to be able to search teh file through the open file window and choose the text file. Once they click the open button then it will import the data into the database. the code I am using is:

    DoCmd.TransferText acImportDelim,"","register","","","",""

    Table name is register

  10. #10
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What is your question? Is this not working?

  11. #11
    Dannat is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Jan 2012
    Posts
    18
    no, nothing is being imported to the table. it sees the txt file, I select it and click open then it dissapears and nothing is imported. So my question I guess is why is nothing being imported tot he table?

  12. #12
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Firstly, you need to give the file name in the transftertext statement.

    Secondly, you may need to have import specifications to align the data in your table correctly. This is optional, but it my be required in this case.

  13. #13
    Dannat is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Jan 2012
    Posts
    18
    So I am guessing that the file name I can get from the coding you gave me which will take whaqt teh user selects and save it in the FileName variable you supplied? as for the aligning, I do not need it, I designed the DB to import with just using the tab as a delimiter.

  14. #14
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In the code I gave you, I used a string called "FileName" - that contains the path and name of the file you are importing.

  15. #15
    Dannat is offline Novice
    Windows 7 32bit Access 2002
    Join Date
    Jan 2012
    Posts
    18
    I will keep on hacking away at it. I appreciate your time and don't want to take too much of it up. I will continue to try to get it working and if after a few more days I am unable I hope I can get your help once more?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 09-13-2011, 01:38 PM
  2. Password Protect button on Switchboard
    By rosaj in forum Access
    Replies: 1
    Last Post: 08-04-2011, 11:08 AM
  3. Switchboard open form based on function value
    By silverspr in forum Forms
    Replies: 5
    Last Post: 03-10-2011, 02:10 PM
  4. Replies: 1
    Last Post: 09-27-2010, 10:10 AM
  5. Replies: 3
    Last Post: 01-14-2010, 08:32 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 - Senior Forums