473,387 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Import File issue

Hi All,
I have the below code but have a couple of problems that I cannot solve, firstly when I select a file the dialog box will promt me to select the file a second time then import, even though it works would like it to import on first select ? also would anyone know how I would write this so it can either import a xls or a txt file depending on file type ? the xls import works fine but when i change it to the acImportDelim it will not (would like both though)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. On Error GoTo Err_Command1_Click
  3.  
  4. Dim dlgOpen As FileDialog
  5. Dim InitialFileName As String
  6. Dim retFile As String, strPath As String
  7.  
  8. Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
  9. With dlgOpen
  10.     .Title = "Select File"
  11.     .AllowMultiSelect = False
  12.     .Filters.Add "CSV Files Only", "*.csv", 1
  13.     .InitialFileName = "C:\"
  14.     .Show
  15.    If .Show = -1 Then strPath = .SelectedItems(1)
  16. End With
  17.    If strPath <> "" Then
  18.    retFile = Right(strPath, Len(strPath) - InStrRev(strPath, "\"))
  19.    retFile = strPath
  20.  
  21.   DoCmd.TransferSpreadsheet acImport, (acSpreadsheetTypeExcel8), "tbltest1", "Test"
  22.   'DoCmd.TransferText acImportDelim, , "tbltest2", "MiscPLRep"
  23.  
  24.     MsgBox ("Finished importing File")
  25.    End If
  26.  
  27. Exit_Command1_Click:
  28. Exit Sub
  29.  
  30. Err_Command1_Click:
  31. If Err.Number = 3011 Then
  32. MsgBox strFile_Path & " is not a valid file, please try again", vbExclamation, "Invalid File"
  33. Else
  34. MsgBox Err.Description
  35. End If
  36. Resume Exit_Command1_Click
  37.  
  38.  
  39. End Sub
  40.  
Thanks
Dec 21 '09 #1
3 2149
MikeTheBike
639 Expert 512MB
Hi

I never use DoCmd.TransferSpreadsheet (or any DoCmd.Transfer...) commands so cannot comment on their operation but to eliminate double dialogue I suggest this

Expand|Select|Wrap|Line Numbers
  1. With dlgOpen 
  2.     .Title = "Select File" 
  3.     .AllowMultiSelect = False 
  4.     .Filters.Add "CSV Files Only", "*.csv", 1 
  5.     .InitialFileName = "C:\" 
  6.     If .Show = -1 Then 
  7.         strPath = .SelectedItems(1) 
  8.     else
  9.         exit sub
  10.     end if
  11. End With 
  12.  
ie. you only need '.Show' once because the Show method dosed what is says (shows the Dialogue!)


MTB
Dec 21 '09 #2
Thanks Mike, cannot beleive I did not see that !!! - works now just need to resolve the docmd piece.
Dec 21 '09 #3
Hi All,

Does anyone know how to get the Docmd.Transfer to work regardless whether it is a txt or xls file ??? I would like both - also is it possible to not have a file name ? the file name I would be selecting changes daily (i.e. nigel_221209)

Thanks
Dec 22 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

97
by: Kjetil Torgrim Homme | last post by:
often when re-factoring code, I need to change the indent level of some chunk of code. due to the lack of an end marker, my Emacs has to use heuristics when re-indenting, and this will...
4
by: MackS | last post by:
Hi I'm new to Python, I've read the FAQ but still can't get the following simple example working: # file main_mod.py: global_string = 'abc' def main():
4
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as...
2
by: David Berry | last post by:
Hi All. I'm looking for any help or sample code that can show me how to make a file import wizard in ASP.NET (VB preferred) like the one that MS Access uses. I'm working on a web site where the...
3
by: Anthony Robinson | last post by:
I have an issue I've been working on that has proven to be quite troublesome. I already have an idea of what the anwser may be, but would like to solicit some suggestions or other ideas from you...
4
by: Steve Jorgensen | last post by:
I'm restarting this thread with a different focus. The project I'm working on now id coming along and will be made to work, and it's too late to start over with a new strategy. Still, I'm not...
7
by: Joe Fallon | last post by:
I am importing a delimited ASCII text file into a dataset using OLEDB. I set up the connection and dataadapter and then fill the dataset. It works - sort of. It turns out that some of my data is...
49
by: Martin Unsal | last post by:
I'm using Python for what is becoming a sizeable project and I'm already running into problems organizing code and importing packages. I feel like the Python package system, in particular the...
2
by: Bill Jackson | last post by:
Once again, I am having issues with imports... Until now, I thought the general guidelines were to rarely use 'from x import y' syntax, except when you really want to copy names over. However, I...
5
geolemon
by: geolemon | last post by:
Import text wizard says: I'm banging my head on this one, here's why: I've been importing files using this process and data format, with success! I created a temporary table in Access to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.