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

how to iterate records of a form in datasheet

6
Hi, this is what I'm doing:

1 - create a table [2 fields], let's call it "greetings". Populate it with 5 records:

field1 , field 2
==========================
hi , bye
hola , adios
hein , struchtlicht
bon jour, au revoir
hallo , ha det

2 - create a form with the datasheet default view

3 - Whenever i add a new record (using the form), i want to write a sub that displays a msgbox with the values of field 1. (hi, hola, hein, bon jour, hallo)

I've tried different stuff with recordsets but i all get are errors.

Thanks
Aug 31 '15 #1

✓ answered by ADezii

  1. Assuming your Form is based on a Table named tblGreetings with 2 Fields:
    1. [Field1] {TEXT}
    2. [Field2] {TETXT}
  2. Your Form consists of at least 2 Fields whose Control Sources are : [Field1] and [Field2].
  3. In the AfterUpdate() Event of your Form, place the following Code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_AfterUpdate()
    2. Dim MyDB As DAO.Database
    3. Dim rst As DAO.Recordset
    4. Dim strBuild As String
    5.  
    6. Set MyDB = CurrentDb
    7. Set rst = MyDB.OpenRecordset("tblGreetings", dbOpenForwardOnly)
    8.  
    9. With rst
    10.   Do While Not .EOF
    11.     strBuild = strBuild & ![Field1] & ", "
    12.       .MoveNext
    13.   Loop
    14. End With
    15.  
    16. If strBuild <> "" Then MsgBox Left$(strBuild, Len(strBuild) - 2)
    17.  
    18. rst.Close
    19. Set rst = Nothing
    20. End Sub
    21.  
  4. OUTPUT (String in Msgbox() after adding a New Record):
    Expand|Select|Wrap|Line Numbers
    1. hi, hola, hein, bon jour, hallo, New Field1 Value

3 1330
ADezii
8,834 Expert 8TB
  1. Assuming your Form is based on a Table named tblGreetings with 2 Fields:
    1. [Field1] {TEXT}
    2. [Field2] {TETXT}
  2. Your Form consists of at least 2 Fields whose Control Sources are : [Field1] and [Field2].
  3. In the AfterUpdate() Event of your Form, place the following Code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_AfterUpdate()
    2. Dim MyDB As DAO.Database
    3. Dim rst As DAO.Recordset
    4. Dim strBuild As String
    5.  
    6. Set MyDB = CurrentDb
    7. Set rst = MyDB.OpenRecordset("tblGreetings", dbOpenForwardOnly)
    8.  
    9. With rst
    10.   Do While Not .EOF
    11.     strBuild = strBuild & ![Field1] & ", "
    12.       .MoveNext
    13.   Loop
    14. End With
    15.  
    16. If strBuild <> "" Then MsgBox Left$(strBuild, Len(strBuild) - 2)
    17.  
    18. rst.Close
    19. Set rst = Nothing
    20. End Sub
    21.  
  4. OUTPUT (String in Msgbox() after adding a New Record):
    Expand|Select|Wrap|Line Numbers
    1. hi, hola, hein, bon jour, hallo, New Field1 Value
Aug 31 '15 #2
zeta
6
thanks for your answer.
Aug 31 '15 #3
ADezii
8,834 Expert 8TB
You are more than welcome.
Aug 31 '15 #4

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

Similar topics

0
by: Malcolm Cook | last post by:
I've discovered: Using "File > Print Preview" in a form's datasheet view with a server Filter crashes access after previewing... ....that is, unless ServerFilterByForm has been turned off...
2
by: steph | last post by:
Hi all, I have an Access2002 form in in datasheet view. Column "CMP" is locked to user input, instead it is filled automatically by this function: === Private Sub Form_BeforeInsert(Cancel As...
1
by: igniztion | last post by:
Hi, When I paste several rows into datasheet view in MS Access, does this trigger a single INSERT with all the rows, or is it counted as one INSERT statement per row? Vegard
3
by: Danny J. Lesandrini | last post by:
-- previously posted on newsgroup :: <microsoft.public.access-- Has anyone else noticed this behavior? Focus jumping from current cell to upper left in embedded datasheet. If not, would you be...
1
by: icenemesis | last post by:
I have a form that searches dynamically based on what criteria the user enters. The resulting query populates a subform in datasheet view. If I wanted to have a button that would export the...
2
by: curran.george | last post by:
'add one textbox to form1 with Control Source property = ID 'copy/paste the form_load code below: 'Then open the form and then attempt to sort the datasheet 'crashes 2003, error 3450 Access 2007 -...
2
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ...
2
by: zandiT | last post by:
hello i have an access database which ive just put on a shared folder on the network for users to use. i tested it well, exported all the objects in a new database, converted to to an mde file,...
1
by: neosp17 | last post by:
HI, I have sub form with checkbox as one checkbox column , name, total amount owned. Only one record from the sub form can be ticked (checked) Question: how to make only one checkbox ticked in sub...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.