Solved

edit a field using VBA...

Posted on 2006-11-24
5
838 Views
Last Modified: 2008-03-01
Hi! I have a table like this...

ID      NUM      NGROUP      
1                   187      
2      187            
3      2689            
4      4901            
5      2521            
6      2433
7                   210      
8      210            
9      934            
10      1333            
11      736            
12                   218               
13      218            
14      2450            
15      653            

the problem is that i have to assign the value for NGROUP (second column) for all the records.

e.g. records from 2 to 6 should receive group 187
      records from 8 to 11 should receive group 210
      records from 13 to 15 should receive group 218

and so on on the whole table...

any clues?

the vba should actually read the NGROUP field of every record and copy it in the following ones until it finds a new value that is not null....

what is the best way to put some order in this table???

thanks in advance!!!


     
0
Comment
Question by:catalini
5 Comments
 
LVL 9

Expert Comment

by:pradapkumar
ID: 18007120
Hi post some more details about your problem as detailed example.
0
 
LVL 84
ID: 18007173
How do you determine what NGROUP a particular record belongs to? For example, why does record #6 belong to NGROUP 187 and not 210? Without some form of logical grouping, you'll not be able to determine which records belong to what NGROUP.
0
 
LVL 15

Accepted Solution

by:
jmantha709 earned 500 total points
ID: 18007174
Something like this (Put this sub in a new module, adjust it for your needs, change the table name and try it... Make a backup first) :

Public sub ArrangeTable()

dim rs as dao.recordset
dim strGroup as string

strGroup = ""
set rs = currentdb.openrecordset("YourTableName")

do while not rs.eof
  If rs("NGROUP") <> "" Then
    strGroup = rs("NGROUP")
  Else
    rs.edit
      rs("NGROUP") = strGroup
    rs.Update
  End if
  rs.movenext
loop
rs.close

End Sub
0
 
LVL 15

Expert Comment

by:jmantha709
ID: 18007178
Replace this line :

set rs = currentdb.openrecordset("YourTableName")

With :

set rs = currentdb.openrecordset("SELECT * FROM YourTableName ORDER BY ID")
0
 

Author Comment

by:catalini
ID: 18007370
LSMconsulting... the group goes in ascending order... following the ID structure...

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now