Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Importing / Page Printing 2

Status
Not open for further replies.

popalu

Programmer
Apr 8, 2004
31
GB
I have 2 questions which I am stuck on, can anyone help.
I am using Access 2000

1. I am using the "DoCmd.TransferText acImportFixed" to import a fixed length text file. The file imports correctly, but the name of the file changes all the time, so how do I open a search box to select the file from a directory, rather than hard code the location and is it possible in A2K?

2. I want to print out a report based on the imported data. Without going to the FILE menu, is there a way, which allows me to select which pages of the report to print, the print range?

eg. I may only want to print pages 1,2 and 23 of a 50 page report, at the moment this is possible using the FILE menu and selecting the print range, but again is this possible from within the code?

Any help is really appreciated.
 
popalu,

1. You need to use the FILEOPEN dialog box. The are two ways of doing this. You can either use a call to the Common Dialog control, or pass a call directly to the Windows API. I prefer the second method. Details of both can be found here:


2. There are methods for displaying the print dialog box to specify printing options but you can probably use the DoCmd.Printout method, which takes arguments that allow you to specify print range. It would be easy enough to create an Access form to specify which pages you want to print in textboxes and pass these values as arguments to the Prinout method.

Ed Metcalfe.

Please do not feed the trolls.....
 
Cheers, I will give them both a go and see if it works.

Thanks for the help mate
 
Step two worked fine.

For step one, I followed the links but can't seem to get the code samples to work, they are coming with all sorts of erors on undefined calls, etc.

I just want to open a box, find and point ot a file and get it's name, then the transfer command can do the rest.
I will have a play about and see if I am doing somehting stupid
 
I have used the following code to get a pick box to pop up when a button on a main is pressed, the user selects the file and this is used as the import into the table.

This all works fine, but how do I get the pick box to start in a particular directory, rather than the root and having to navigate from there to the path I want. The second time you import the navigated to directory is correct, but when you start out, the root is the starting place.

The 'Backup' macro just copies the data currently held in the main table into a duplicate table in case of errors when importing new data files.

The 'Delete' macro emptys the main table ready for the imported data.

There is another button on the form which reverses the whole process, if the import data is incorrect, as defined in the schema.ini file

Code:
Private Sub Command0_Click()

Dim filename As String

    Dim fd As FileDialog

    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    Dim vrtSelectedItem As Variant

    With fd
       If .Show = -1 Then
            For Each vrtSelectedItem In .SelectedItems
             filename = vrtSelectedItem
            Next vrtSelectedItem
        Else
         Exit Sub
        End If
    End With

   Set fd = Nothing

   DoCmd.RunMacro "Backup"
   DoCmd.RunMacro "Delete"
   DoCmd.TransferText acImportFixed, "Gemalto", "DataFile", filename
  
   Me.Refresh
End Sub
 
how do I get the pick box to start in a particular directory
...
With fd
.InitialFileName = "\path\to\directory"
If .Show = True Then
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the help, all working fine now.

Both have a star for your help with this problem, what would we do without the internet and the help people give?

Probably be sat scratching our heads and buying mountains of books until a brainwave or a book showing the exact problem turned up
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top