A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Importing Text



 
 
Thread Tools Display Modes
  #1  
Old February 9th, 2009, 04:59 PM posted to microsoft.public.access.gettingstarted
Bre-x
external usenet poster
 
Posts: 103
Default Importing Text

Hi, I need some help importing a tool list from Mastercam. Here is the Text
File

# = 1
Type = Center Drill
Tool name = 1/8 CENTERDRILL
Diameter = 0.125000
Rad. Type = None
Cor. rad. = 0.000000
Threads = 0.000000

# = 2
Type = Center Drill
Tool name = 1/4 CENTERDRILL
Diameter = 0.250000

# = 3
Type = Center Drill
Tool name = 1/2 CENTERDRILL
Diameter = 0.500000
Cor. rad. = 0.000000

..............etc, etc, etc

I need to go into each "# =" occurrence then import into a table

TID, Type, Tool, Diameter
1, Center Drill, 1/8 CENTERDRILL, 0.125000
2, Center Drill, 1/4 CENTERDRILL, 0.250000
3, Center Drill, 1/2 CENTERDRILL, 0.500000

The "Type, Tool, and Diameter" are always the first 3 Lines After the Tool
ID: " # = "


Thank you all,

Bre-x


  #2  
Old February 9th, 2009, 05:22 PM posted to microsoft.public.access.gettingstarted
Bre-x
external usenet poster
 
Posts: 103
Default Importing Text

Thanks!!

Dim strFile As String
Dim intFile As Integer
Dim strInput As String
Dim db As Database
Dim rs As Recordset

strFile = "N:\1CNC\TOOLLST.TXT"
intFile = FreeFile
Set db = DBEngine(0)(0)
Set rs = db.OpenRecordset("tblTool")
Open strFile For Input As intFile
Do
Line Input #intFile, strInput
If Left(strInput, 3) = "# =" Then
rs.AddNew
rs!ToolNumber = Mid(strInput, 4)
ElseIf Left(strInput, 4) = "Type" Then
rs!ToolType = Mid(strInput, 8)
ElseIf Left(strInput, 9) = "Tool name" Then
rs!ToolName = Trim(Mid(strInput, 12))
ElseIf Left(strInput, 8) = "Diameter" Then
rs!Diameter = Trim(Mid(strInput, 11))
ElseIf Left(strInput, 8) = "Material" Then
rs!mat = Trim(Mid(strInput, 11))
rs.Update
End If
Loop Until EOF(intFile)

rs.Close
Set rs = Nothing
Set db = Nothing


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:50 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.