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

Accessing each Character in the Record Field

subedimite
In VBA Access,

How can I read a filed from a table and then read each record in the field and then access each character insided the record for that filed. should I use a split function.

I tried this
Expand|Select|Wrap|Line Numbers
  1. Do Until recordset1.EOF
  2.  
  3.   UpdateTable_sub_data = findSubCommands(recordset1![data])
  4.  
  5.   recordset1.MoveNext
  6.  
  7.  Loop
  8.  
  9.  Debug.Print UpdateTable_sub_data(0)
  10.  
  11.  
  12.  
  13. ------------------------------------------------------------------------------
  14. Function findSubCommands(str As String)
  15.  
  16.  findSubCommands = Split(str, "+")
  17.  
  18. End Function
After doing this, I can only print the first data filed .
if I try, Debug.Print UpdateTable_sub_data(1)
The script out of range. Why there is not second record in the array??
Apr 15 '10 #1
9 2934
NeoPa
32,556 Expert Mod 16PB
I'm confused by your use of the terminology. Data in Access is stored within a field. Fields fit together into a record and records make up a table.

To access data within a field you would first need to ensure that it is text data. If not, it could possibly be converted to text using a function such as Format(). Accessing individual characters within such a string is fairly straightforward and done by using the Mid() function. A loop of some kind would enable all characters to be accessed in order.

Welcome to Bytes!
Apr 15 '10 #2
ADezii
8,834 Expert 8TB
The following code will extract every Character in a Field named [Location] for every Record in a Table named Training_Events. What you do with each Character is up to you.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim intNumOfCharsInField As Integer
  4. Dim intCharCtr As Integer
  5. Dim strChar As String
  6.  
  7. Set MyDB = CurrentDb
  8. Set rst = MyDB.OpenRecordset("SELECT [Location] FROM Training_Events", dbOpenForwardOnly)
  9.  
  10. With rst
  11.   Do While Not .EOF
  12.     If Not IsNull(![Location]) Then
  13.       intNumOfCharsInField = Len(![Location])
  14.         For intCharCtr = 1 To intNumOfCharsInField
  15.           'Here is where each Character would be analyzed
  16.           strChar = Mid$(![Location], intCharCtr, 1)
  17.         Next
  18.     Else
  19.       'Whatever you wish to do with NULL Fields
  20.     End If
  21.       .MoveNext
  22.   Loop
  23. End With
  24.  
  25. rst.Close
  26. Set rst = Nothing
Apr 15 '10 #3
Thanks for that. The Mid fucntion seemed to be appropriate for me. If I want to use the split function ( for the recordset) to split the table field and store in array where each index is a record in that filed, what should I use as the delimeter, is that carriage return.


Sorry! I might have been saying something not directly. All wanted to do was sace each record of a filed in a string array and then access each caharecter as above so that I might have to replace some characters from other table.



Thanks heaps
Apr 16 '10 #4
NeoPa
32,556 Expert Mod 16PB
Node elements in a recordset are field values. As such, you are starting with strings or numbers. I have great difficulty trying to work out what your question means as you are not using the terms in a meaningful way. I mentioned this in my first post. It is important to use the correct words when talking or writing, otherwise it can be very difficult to even guess what you're trying to say.

In short, I can see no situation here where Split() would be required, but then I may be missing something as I have very little idea what you're trying to say.
Apr 16 '10 #5
ADezii
8,834 Expert 8TB
If you wish to extract Field Values from a Recordset, and place them into an Array, then The GetRows() Method is what you are looking. I'm posting a Link to an Article that describes the use of this Method below. Like NePa, Iam confused by the nature of your request, and I see no possible use of the Split() Function in this context.
How to Use the GetRows() Method in DAO
Apr 16 '10 #6
Yes that is right.

I do get bit impatience while while writing these requests. I will keep in mnd about this one and make a better habit.

Yep this what exactly what I wnat to do. It must be one of the very common thing to do in db programming.

Let my try this one. Cheers!
Apr 19 '10 #7
your help has been pretty helpful. Thanks.
Apr 19 '10 #8
NeoPa
32,556 Expert Mod 16PB
That's fine.

Let us know how you get on with it.
Apr 19 '10 #9
It went pretty well Thanks. I am a pretty new VBA user but I am getting there:)
Apr 20 '10 #10

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

Similar topics

1
by: Alistair Hopkins | last post by:
Hi, I am trying to write a generic audit-trail trigger function which will record changes on a field-by-field basis to a single table for all audited tables. However, I find that I can only...
2
by: ggnanaraj | last post by:
In AS/400, have a table that has a character field defined. This has to be converted to date format of YYYY-MM-DD. The sample character data is as follows: 02/05/2005. In UDB, you can do a...
3
by: tony bergstrom | last post by:
Ok, so I have a Form. It is a continuous form. In the header one selects what person to view data for. Once the person is selected, the travel information that has been budgeted for the year...
33
by: Steven Taylor | last post by:
Hope someone can help. This is half an Access question. The half I'm using is Access Xp as a backend data file. I'm using ODBC to connect to the data file. All commands are via SQL type...
3
by: ILCSP | last post by:
Heello, I'm using Access 2000. I have a form with a combo box that has a query as its row source and it's bound to column 1. This combo box is unbound to a record like the rest of the form...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
2
by: Gerald Aichholzer | last post by:
Hello NG, I have the following XML (simplified) having a variable number of v-elements: <record> <field name="parameter"> <v0>paramname0</v0> <v1>paramname1</v1> <v2>paramname2</v2>
1
by: Montana_Trader | last post by:
I have a product database that includes a memo field for product descriptions. That database must be imported into a legacy system that has four text fields for product descriptions, each with a...
4
by: John Kotuby | last post by:
Hi all, I am using a Repeater in conjunction with a SQLDatasource and SQL Server. One of the controls in the repeater is a HyperlLink as follows: <asp:HyperLink...
1
by: Peter Robinson | last post by:
Dear list I am at my wits end on what seemed a very simple task: I have some greek text, nicely encoded in utf8, going in and out of a xml database, being passed over and beautifully displayed...
0
BarryA
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.