473,396 Members | 2,098 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 do I move to the previous field in a recordset?

gnawoncents
214 100+
I am pretty inexperienced with VBA recordsets, and hope there is a simple fix to my problem. I have a recordset (rstQuestions) and am using a For Each...Next operation to go through the fields (fldQuestions) and pull data from relevant ones. I'm running into a problem though when I try to navigate to the previous field (not record).

Here's what I'm trying to do... I need to find the relevant field in a recordset (done; no problems), move to the next field in that same record, retrieve and store the field's value in a string, then return to the previous field for further processing.

I have tried fldQuestions.MovePrevious and fldQuestions.MoveNext, but those seem reserved for records, not fields. (I get an "Error 438: Object doesn't support this property or method.")

I even experimented with "Next fldQuestions" and "Previous fldQuestions," with equally poor results.

Is what I'm attempting possible? If so, what is the correct syntax?

I know I could get the same data with a DLookup function, but since my code runs through every field of every record, I'm pretty sure that would slow down the procedure significantly.

Any ideas? Thank you in advance for your help.
Sep 20 '10 #1

✓ answered by Mariostg

I think I understand better what you want to do. This snippet should give you a good clue
Expand|Select|Wrap|Line Numbers
  1.     Dim f As String
  2.     f = "YourDesiredFieldName"
  3.     rs.Open sql, cn
  4.     strComments = Nz(rs.Fields(f), "")
  5.  

7 2366
Mariostg
332 100+
YourRecordSet!YourFieldName to select a specific field value at a given recordset row.

Ex:
rs.open sql, cn
rs.MoveFirst 'Moves to first Record
x=rs!YourFieldName 'Assign the value of YourFieldName value to x.
Sep 20 '10 #2
gnawoncents
214 100+
Thanks for the reply.

Since the field name in question changes with each iteration of the procedure, I had previously tried a variation of your suggestion:

strComments = Nz(rstQuestions!(strLOOKUP), "")

...where strLOOKUP is the field name I need.

However, I got the compile error, "Type-declaration character does not match declared data type."

What am I missing here?
Sep 20 '10 #3
Mariostg
332 100+
It's rstQuestions!(strLOOKUP) that creates the error. No brackets...rstQuestions!strLOOKUP
Sep 20 '10 #4
gnawoncents
214 100+
When I remove the parentheses, then it just looks for a field named "strLOOKUP," which doesn't exist. Is there a better way to indicate strLOOKUP is a string than parentheses?
Sep 20 '10 #5
Mariostg
332 100+
I think I understand better what you want to do. This snippet should give you a good clue
Expand|Select|Wrap|Line Numbers
  1.     Dim f As String
  2.     f = "YourDesiredFieldName"
  3.     rs.Open sql, cn
  4.     strComments = Nz(rs.Fields(f), "")
  5.  
Sep 20 '10 #6
gnawoncents
214 100+
Thanks! It seems to be working now. I was missing the ".Fields" portion of the code. Sorry for not explaining myself better earlier.
Sep 20 '10 #7
Mariostg
332 100+
No problem. Glad it is working. You might want to mark your post as solved.

Never Mind... you did mark it.
Sep 20 '10 #8

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

Similar topics

5
by: Elvis V. | last post by:
Good morning, I have a table with three fields, Buildings, Floors and Rooms. This is what I would like to do; in my form when I select Building1 in my drop down box for Buildings, when I go to the...
3
by: Bill Clark | last post by:
I have about 20,000 records pulled from Excel that I need to update. What I need to do is run an update query that bascially says: If a field is null, update it with the previous record value of...
2
by: Mike | last post by:
I'm sure this has been covered before in the newsgroup but have had no luck locating it. I have two tables: InstMonitors & MonModDesc Structure of MonModDesc: Model, Description Structure...
2
by: Anand Ganesh | last post by:
Hi All, How to Implement Move Next, Move Previous, Last Record and First Record in a DataGrid Control ? Is there any standard tool available in the tool box button? Thanks for your time. ...
6
by: abbylee26 | last post by:
Im comparing values in a field while doing a loop if sAct<>myData(5,i) then At the end of the loop I make the value of sAct equal the current myData This will work when comparing other fields...
2
by: sarah | last post by:
Hi there Hope someone can help - this is driving me mad. I have been able to complete this using Access 97 but not Access 2003. I would like to make a field enabled after the previous field has...
1
by: Rajasuds | last post by:
I have a question in MS Access I have two tables MASTER with Fields 1, Field 2, Field 3 TRANS with Field1, Field 2, Field,10 I need to set up a look up condition where, I need !Field 2 to...
2
by: ashasprabhu | last post by:
hai, How to move records to next and previous in asp.net as we do in VB6.0
3
by: jej1216 | last post by:
I have a form in which a select field lists 5 items pus the option of "Other." I want a text field to be hidden unless the select field value is "Other." The form is HTML, but I am assuming that I...
2
by: edcha | last post by:
I have the Next XML var xml = new XElement( "clients", new XElement("client", new XAttribute("id",1), new XElement( "name", "Luis"), new XElement( "country", "Portugal") ), new...
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:
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...
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...
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
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
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...

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.