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) -
Private Sub Command1_Click()
-
On Error GoTo Err_Command1_Click
-
-
Dim dlgOpen As FileDialog
-
Dim InitialFileName As String
-
Dim retFile As String, strPath As String
-
-
Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
-
With dlgOpen
-
.Title = "Select File"
-
.AllowMultiSelect = False
-
.Filters.Add "CSV Files Only", "*.csv", 1
-
.InitialFileName = "C:\"
-
.Show
-
If .Show = -1 Then strPath = .SelectedItems(1)
-
End With
-
If strPath <> "" Then
-
retFile = Right(strPath, Len(strPath) - InStrRev(strPath, "\"))
-
retFile = strPath
-
-
DoCmd.TransferSpreadsheet acImport, (acSpreadsheetTypeExcel8), "tbltest1", "Test"
-
'DoCmd.TransferText acImportDelim, , "tbltest2", "MiscPLRep"
-
-
MsgBox ("Finished importing File")
-
End If
-
-
Exit_Command1_Click:
-
Exit Sub
-
-
Err_Command1_Click:
-
If Err.Number = 3011 Then
-
MsgBox strFile_Path & " is not a valid file, please try again", vbExclamation, "Invalid File"
-
Else
-
MsgBox Err.Description
-
End If
-
Resume Exit_Command1_Click
-
-
-
End Sub
-
Thanks
3 2149
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 - With dlgOpen
-
.Title = "Select File"
-
.AllowMultiSelect = False
-
.Filters.Add "CSV Files Only", "*.csv", 1
-
.InitialFileName = "C:\"
-
If .Show = -1 Then
-
strPath = .SelectedItems(1)
-
else
-
exit sub
-
end if
-
End With
-
ie. you only need '.Show' once because the Show method dosed what is says (shows the Dialogue!)
MTB
Thanks Mike, cannot beleive I did not see that !!! - works now just need to resolve the docmd piece.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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():
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
| |