Hi anyone!
I am working to translate an Excel macro into Access and I'm having little luck with a couple lines of code. I can't figure out how to prompt the user to select a file (not to past a path and filename) but to actually browse for a file :) Here is the Excel code I already have:
Dim TxtName As String
TxtName = Application.GetOpenFilename("TextFiles (*.txt), *.txt", , "Select The file you wish to update:")
I'm also hoping to strip off the first few blank lines from the text file I am importing. In excel it was easy because I could simply tell the program to look at the 4th line in the text file:
'Import the .txt file:
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & CStr(TxtName), Destination:=Range("A1"))
.TextFileStartRow = 4
But my macro in Access doesn't seem to give that option. All I have in access so far is:
DoCmd.TransferText acImportDelim, "InventoryObsoSpec", NewTableName, filename, No
But that grabs a bunch of blank lines into my data table. Can anyone help me out there???
Thanks!
2 35781
You will need to add a refference to MS Office, go into the VBA window - Tools -References - Function FindTxtFile(strFNme As String, strSearchPath As String) As String
-
' Displays the Open dialog box for the user to locate
-
' the BackEnd database. Returns the full path.
-
Dim myDialog As FileDialog
-
'Declare a variable as a FileDialogFilter object.
-
Dim vrtSelectedItem As Variant
-
'Set the FileDialogFilters collection variable to
-
'the FileDialogFilters collection of the SaveAs dialog box.
-
Set myDialog = Application.FileDialog(msoFileDialogOpen)
-
With myDialog
-
.AllowMultiSelect = False
-
.Filters.Add "Text", "*.txt", 1
-
.Title = "Where Is The Text File?"
-
' Debug.Print Right(strSearchPath, Len(strSearchPath) - 10)
-
.InitialFileName = strSearchPath & strFNme
-
If .Show = -1 Then
-
For Each vrtSelectedItem In .SelectedItems
-
FindTxtFile = Trim(vrtSelectedItem)
-
Next vrtSelectedItem
-
Else
-
End If
-
Set myDialog = Nothing
-
End With
-
End Function
-
Hi anyone!
I am working to translate an Excel macro into Access and I'm having little luck with a couple lines of code. I can't figure out how to prompt the user to select a file (not to past a path and filename) but to actually browse for a file :) Here is the Excel code I already have:
Dim TxtName As String
TxtName = Application.GetOpenFilename("TextFiles (*.txt), *.txt", , "Select The file you wish to update:")
I'm also hoping to strip off the first few blank lines from the text file I am importing. In excel it was easy because I could simply tell the program to look at the 4th line in the text file:
'Import the .txt file:
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & CStr(TxtName), Destination:=Range("A1"))
.TextFileStartRow = 4
But my macro in Access doesn't seem to give that option. All I have in access so far is:
DoCmd.TransferText acImportDelim, "InventoryObsoSpec", NewTableName, filename, No
But that grabs a bunch of blank lines into my data table. Can anyone help me out there???
Thanks!
-
-
Dim TxtName As String
-
dim strLine as string
-
TxtName = Application.GetOpenFilename("TextFiles (*.txt), *.txt", , "Select The file you wish to update:")
-
open txtname for input as #1
-
for I = 1 to 5
-
Line Input #1, strLine
-
next I
-
do until eof(1)
-
Line Input #1, strLine '<--now you're on record 5...what do you want to do with it?
-
'do your stuff here
-
loop
-
close #1
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: andreas |
last post by:
Hi there,
I have the following situation:
1. DOT.NET Application is started
2. DOT.NET Application instantiates Access.Application.8
3. Opens a specified database (MDB)
4. DOT.NET...
|
by: Big Time |
last post by:
I'm looking into buying a book to learn Access VBA programming. I am very
familiar with Access however I am new to programming Access with VBA. Are
there any recommendations for books for...
|
by: Cheryl Langdon |
last post by:
Hello everyone,
This is my first attempt at getting help in this manner. Please
forgive me if this is an inappropriate request.
I suddenly find myself in urgent need of instruction on how to...
|
by: hedgracer |
last post by:
I have a strange problem with a docmd.transfertext statement. I have
set up an import specification to transfer in a .txt file by fixed
width. When I do the import using the specification the file...
|
by: Darryl Kerkeslager |
last post by:
Currently I am using the RegExp object to parse a large dataset in an Access
table - but this table was exported from SQL Server, and the very correct
question was asked - why not just do it in SQL...
|
by: Konrad Hammerer |
last post by:
Hi!
I have the following problem:
I have a query (a) using another query (b) to get the amount of records
of this other query (b), means:
select count(MNR) as Number from...
|
by: JFKJr |
last post by:
Hi, the following Excel VBA code is used to select 5 rows by double clicking the cell in the first column corresponding to that row. The code is working fine in excel.
But, I need Access VBA code,...
|
by: JFKJr |
last post by:
Hello everyone,
I have added a ComboBox in excel spreadsheet using the following Access VBA code.
Public eXL As New eventsXL
Function Create_ComboBox()
With eXL
If .XL Is Nothing Then Set...
|
by: JFKJr |
last post by:
Hello everyone, the following Access VBA code opens an excel file and creates textboxes in a given range of cells dynamically. The code attaches "MouseUP" and "Exit" events to the textboxes (using...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |