473,396 Members | 1,996 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.

beginner question - assign value of field to variable

rev
Trying to teach myself Access. All I want to do at the moment is loop
through a column and display each row one at a time in a messagebox.
Here's what I have so far:

Private Sub Command0_Click()
DoCmd.OpenTable "mytable"
DoCmd.GoToRecord , , acFirst
DoCmd.GoToControl "myfield"
x = currentrecord.value '>>>this doesnt work...
MsgBox x
total = DCount("*", "mytable") - 1
For x = 1 To total
DoCmd.OpenTable "mytable"
DoCmd.GoToRecord , , acNext
DoCmd.GoToControl "myfield"
x = ???
MsgBox x
Next
End Sub

Any assistance would be GREATLY appreciated!

Jul 10 '07 #1
1 3946
It would be easier to open a recordset if you wanted to loop through the
records.

Here's an example:
http://allenbrowne.com/func-DAO.html...cordsetExample
It lists the records to the Immediate Window (Ctrl+G) rather than a MsgBox
for each one.

If you need to do this in a form, you can use the RecordsetClone of the
form, i.e.:
Set rs = Me.RecordsetClone
rs.MoveFirst
...

And here's a list of the kind of things people normally get into trouble
with when using recordsets:
Traps: Working with Recordsets - 10 common mistakes
at:
http://allenbrowne.com/ser-29.html

BTW, if you have a background in other databases, you may loop through
recordsets less frequently in Access. You can often perform an operation by
executing one action query instead of visiting each record in turn.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"rev" <sn*********@yahoo.comwrote in message
news:11**********************@o11g2000prd.googlegr oups.com...
Trying to teach myself Access. All I want to do at the moment is loop
through a column and display each row one at a time in a messagebox.
Here's what I have so far:

Private Sub Command0_Click()
DoCmd.OpenTable "mytable"
DoCmd.GoToRecord , , acFirst
DoCmd.GoToControl "myfield"
x = currentrecord.value '>>>this doesnt work...
MsgBox x
total = DCount("*", "mytable") - 1
For x = 1 To total
DoCmd.OpenTable "mytable"
DoCmd.GoToRecord , , acNext
DoCmd.GoToControl "myfield"
x = ???
MsgBox x
Next
End Sub

Any assistance would be GREATLY appreciated!
Jul 10 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Terry | last post by:
I have a number of input boxes used to display totals based on selected items for each row in a table. There are more than a few rows that are identical, except for the form field name. I have...
3
by: Wilson Wu | last post by:
Hi, How can I find the field value in the dataset and then assign one of the field value to a variable ? Thanks Wilson
6
by: Chris | last post by:
Hi all, I've recently discovered the joys of tag :) I have a ListView which is populated with strings from a List<>, and each ListView item is linked to the relevant object in List<> using Tag....
1
by: c_beginner | last post by:
yes, this is my how work question. Since I am lack in getting an assistance with my lab work I put this in this advance group. Sorry for the trouble I am making. Write a program to calculate the...
2
by: Jim McGivney | last post by:
In asp 2.0 I am trying to insert a row using a detailsview control connected to an accessDataSource. I get the error message below. I am having trouble identifing which data field is causing the...
6
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
3
by: Liam Mac | last post by:
Hi All, Can anyone direct me or provide advice on how I can assign a null value to a date variable in vb.net. Basically what I'm doing is that I'm looping through a recordset where I have three...
3
by: Toni | last post by:
Hello! I'm building an application where the user can update his own personal information in a database using a form. The program fetches the user's information from the database, fills the form...
4
by: philin007 | last post by:
Hi , I have the following javascript codes: ****************************************** <script language="JavaScript"> <!-- .... ..... if (nextRow >5) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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,...

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.