473,396 Members | 1,989 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,396 software developers and data experts.

How import text file to MS Access vba

Down my code is working.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub PR_Click()
  4. Dim intfileH   As Integer
  5.   Dim strBuf     As String
  6.   Dim rst        As DAO.Recordset
  7.   Dim strRec, vBuf, strRecDetail
  8.  
  9.   intfileH = FreeFile()
  10.   Open "D:\pr.txt" For Input As #intfileH
  11.   strBuf = Input(LOF(intfileH), #intfileH)
  12.   Set rst = CurrentDb.OpenRecordset("Table3")
  13.  
  14.   vBuf = Split(strBuf, "")
  15.   For Each strRec In vBuf
  16.      If strRec <> "" Then
  17.         strRecDetail = Split(strRec, vbCrLf)
  18.         With rst
  19.            .AddNew
  20.            !Hcod = Split(strRecDetail(0), ":")(1) 
  21.            !Nhour = Mid(strRecDetail(1), 27, 5)
  22.            !Ehour = Split(strRecDetail(1), "-")(1)
  23.            .Update
  24.         End With
  25.      End If
  26.   Next
  27.  
  28.   rst.Close
  29.   Close (intfileH)
  30.  
  31. End Sub
The code is working.
Apr 6 '17 #1
4 7112
jforbes
1,107 Expert 1GB
You might want to check out this thread: Text file to access Table
Apr 6 '17 #2
NeoPa
32,556 Expert Mod 16PB
I can't make out what the question means but your code shows you need to read Require Variable Declaration.
Apr 6 '17 #3
If your goal is to store some or all data that is in a text file in an Access database, you should import the contents of the file into a new table or append the data to an existing table. You can view and edit the imported data, and the changes you make to the data do not affect the source text file. Have a look on Microsoft blog which may help you.
Apr 14 '17 #4
ADezii
8,834 Expert 8TB
If you could Post some Sample Data, or even Dummy Data representing the File's Structure, I'm sure we can be more helpful.
Apr 15 '17 #5

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

Similar topics

4
by: Kevin Forbes | last post by:
Hi there, When importing a text file using SQL Server, how do I specify the path to a file on the same remote server that SQL Server is running on? I tried //c:/filename but that doesn't seem to...
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: John | last post by:
HI, I'm having trouble importing text files. I had problem with Access '97 that forced me to reinstall. After I did this I couldn't import text files. The Help file recommends reinstall again,...
2
by: VMI | last post by:
In Access, when a user's going to import a fixed-width format ascii file, a window in the "Import Text Wizard" lets the user "mark" where in a string one field will begin and end (with the vertical...
4
by: jmalvika | last post by:
Hi all, I'm trying to generate an excel report from an ASP web page using .. "response.ContentType = "application/vnd.ms-excel" .... I need to add a custom header & footer to the excel...
0
by: erucevice | last post by:
I am trying to bcp a text file that is written out of a Java application. The text file has important order information that I need to bcp into a SQL Server 2000 database. The problem is that when...
3
by: tjuiowa | last post by:
Hi I am trying to import a text file into a MS Access database. The first 11 lines of the text file are in a different format, so i would like to skip those lines and start at line 12. is there...
4
by: angelasg | last post by:
Hello. I am saving an Excel file as a text file then importing it into Access using a specification. One of the fields in the file is a currency formatted with commas. Those numbers over 999...
1
by: Noorain | last post by:
sir my data are in text file. i want import text file in mysql data to use php script. please help me............. my text file is 1#AA#2,345.00 2#BB#850.00 3#CC#31,855.00
15
by: JEFFREY MUSGRAY | last post by:
I have a text file that I want to read and assign parts to a certain field in MS Access table When you look at this file you will see numbers with corresponding info Ex: 120A. CMPBLLBK I want to...
0
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...
1
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...
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
marktang
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,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
agi2029
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,...

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.