473,396 Members | 2,011 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 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 1331
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.