Solved

edit a field using VBA...

Posted on 2006-11-24
5
855 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

828 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