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

Parsing Data in one table (multiple conditions) to several .txt files

Hello, everyone. Please bear in mind that I have a very basic knowledge of VBA, but I think I can understand logic.

I'm looking for a way to build a module that can help me parse the data in one massive table, using "control tables" to determine the valid value set for the fields I need to consider in the selection. I cannibalised a piece of code from a similar post that I think will help me, but need your guidance, by explaining what each of the commands actually do, so I can try it out in my database. I think that I can figure out the rest.

' START CODE <---------------------

Sub loopFiles()

Dim myConn As ADODB.Connection
Set myConn = CurrentProject.Connection
Dim MyRecSet As New ADODB.Recordset
MyRecSet.ActiveConnection = myConn
MyRecSet.Open "Schools", , adOpenStatic, adLockOptimistic ' Comment - suposse I can replace "Schools" with any table in my current DB....
MyRecSet1.Open mySQL, , adOpenStatic, adLockOptimistic ' Comment - What is this?!?

Dim schNbr
Dim mySQL As String


MyRecSet.MoveFirst

While Not MyRecSet.EOF ' While loop that goes through RecordSet for execution - I get this

schNbr = MyRecSet.Fields("No").Value
mySQL = "select * from schools where no = '" & schNbr & "'" ' This I can figure out

Debug.Print mySQL ' debug statement
'DoCmd.RunSQL mySQL, 0 ' for actual execution

MyRecSet.MoveNext
Wend

MyRecSet.Close
Set MyRecSet = Nothing
Set myConn = Nothing

End Sub

' END CODE <---------------------


I wish I could import the data into an Oracle DB and write an SQR for this, but can't, since the team has been using this DB (and plan to use it for years to come).

Thank you very much in advance!

D
Nov 8 '06 #1
2 2622
NeoPa
32,556 Expert Mod 16PB
MyRecSet1.Open mySQL, , adOpenStatic, adLockOptimistic ' Comment - What is this?!?
Open Method (ADO Recordset)
Opens a cursor.
Syntax
recordset.Open Source, ActiveConnection, CursorType, LockType, Options
I 'm not sure exactly what you're after here but if you look in the help system for things you should get fuller info.
I can't see how this line can come before any code that sets up mySQL - a string containing SQL code.
Looks like an 'alternative' bit of code - doesn't go here nor can be run exactly as is, but an example of another approach.
If used, should have extra code in body processing through this recordset.

3 lines before
Expand|Select|Wrap|Line Numbers
  1. MyRecSet.ActiveConnection = myConn
Should probably have a 'Set' before it as it's an object assignment.
Nov 9 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
Any questions let me know ...

Expand|Select|Wrap|Line Numbers
  1.  
  2.  ' as you are putting this in a module I would recommend using Function rather than sub as it is easier to call 
  3. Function loopFiles() 
  4.  
  5. ' create a variable to hold connection to database 
  6. Dim myConn As ADODB.Connection
  7. ' set that connection to current database
  8. Set myConn = CurrentProject.Connection
  9.  
  10. 'create a variable to hold recordset in database (table or query)
  11. Dim MyRecSet As New ADODB.Recordset 
  12.  
  13. 'reference the current database as location of recordset
  14. MyRecSet.ActiveConnection = myConn
  15. 'open the recordset, in this case presumably the Schools table
  16. MyRecSet.Open "Schools", , adOpenStatic, adLockOptimistic 
  17.  
  18. ' Comment - suposse I can replace "Schools" with any table in my current DB....Answer yes, any table or saved query or sql statement
  19.  
  20. 'mySQL refers to a previously defined sql statement
  21. 'Look for 'Dim mySQL As String' - defines string variable to hold sql statement
  22. 'And mySQL="SELECT <Fields> FROM <TableName> WHERE <Criteria>" - Query definition
  23.  
  24. MyRecSet1.Open mySQL, , adOpenStatic, adLockOptimistic ' Comment - What is this?!? - This then opens the query as a recordset
  25.  
  26. Dim schNbr ' defaults to a variant which essentially can hold any type of value
  27. Dim mySQL As String ' see above
  28.  
  29. ' this moves to first record in the recordset
  30. MyRecSet.MoveFirst
  31.  
  32. While Not MyRecSet.EOF ' While loop that goes through RecordSet for execution - I get this (until it reaches end of file)
  33.  
  34. 'Looks for a field in the recordset called "No" and finds its value in the current record then passes it to schNbr variable 
  35. schNbr = MyRecSet.Fields("No").Value 
  36. mySQL = "select * from schools where no = '" & schNbr & "'" ' This I can figure out (See above for opening it as a recordset)
  37.  
  38. Debug.Print mySQL ' debug statement 
  39. 'DoCmd.RunSQL mySQL, 0 ' for actual execution (won't work for a SELECT statement used for UPDATE, DELETE and INSERT statements mostly - i.e. Action queries)
  40.  
  41. MyRecSet.MoveNext ' move to next record
  42. Wend ' loop unless end of file
  43.  
  44. MyRecSet.Close ' all recordsets must be closed
  45. Set MyRecSet = Nothing ' and then variable reset to nothing
  46. Set myConn = Nothing ' don't close database but must reset variable to nothing
  47.  
  48. End Function
  49.  
  50.  
Nov 9 '06 #3

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

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
35
by: .:mmac:. | last post by:
I have a bunch of files (Playlist files for media player) and I am trying to create an automatically generated web page that includes the last 20 or 30 of these files. The files are created every...
2
by: M Wells | last post by:
Hi All, I'm trying to track down a mysterious problem we're experiencing in which updates and inserts to tables in our mssql2k server appear to be 'disappearing.' To explain our situation: ...
7
by: Randy Yates | last post by:
I'm a complete newbie to postgres so please look the other way if these questions are really stupid. Is it legitimate to have one database per data file? For organizational and backup purposes,...
5
by: rAinDeEr | last post by:
Hi, I have a web application with a table to store terms and conditions of a Company. This may some times run into many pages and some times it may be just a few sentences. It is a character...
5
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or...
0
by: Christoph Haas | last post by:
Hi, list... I have written an application in Perl some time ago (I was young and needed the money) that parses multiple large text files containing nested data structures and allows the user to...
1
by: Robert Neville | last post by:
Basically, I want to create a table in html, xml, or xslt; with any number of regular expressions; a script (Perl or Python) which reads each table row (regex and replacement); and performs the...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.