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.
I think I understand better what you want to do. This snippet should give you a good clue -
Dim f As String
-
f = "YourDesiredFieldName"
-
rs.Open sql, cn
-
strComments = Nz(rs.Fields(f), "")
-
7 2366
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.
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?
It's rstQuestions!(strLOOKUP) that creates the error. No brackets...rstQuestions!strLOOKUP
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?
I think I understand better what you want to do. This snippet should give you a good clue -
Dim f As String
-
f = "YourDesiredFieldName"
-
rs.Open sql, cn
-
strComments = Nz(rs.Fields(f), "")
-
Thanks! It seems to be working now. I was missing the ".Fields" portion of the code. Sorry for not explaining myself better earlier.
No problem. Glad it is working. You might want to mark your post as solved.
Never Mind... you did mark it.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
by: ashasprabhu |
last post by:
hai,
How to move records to next and previous in asp.net as we do in VB6.0
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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: 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...
|
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,...
|
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...
|
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...
| |