Tantani


Hellooo,

I use Access VBA 2003 with DAO.

Does anyone know how can I move to the first record of an Quantity attribute in order to change or Edit it like this:

Quantity
0.50
1.40
0.70
.....

Goto first field (0.50), if it is lower than 1, then change it to 0
Goto second
field (1.40), if it is lower than 1, then change it to 0, otherwise change it to 1.


Thank you in advance!



Re: Edit the Recordset

Luiz Claudio - MVP


Hi Tantani,

you can use recordset's MoveFirst and MoveNext methods to navigate through recordset's records. Eg:

Dim db As DAO.Database

Dim rst As DAO.Recordset

Set db=CurrentDB()

Set rst=db.OpenRecordset ("you query", dbOpenDynaset)

With rst

.MoveFirst

.Edit

If !Quantity<1 Then

!Quantity=0

End If

.MoveNext

If !Quantity < 1 Then

!Quantity=0

Else

!Quantity=1

End If

.Update

.Close

End With







Re: Edit the Recordset

Tantani

Dear Luiz Claudio ,

Thank very very much...I really appreciate you for your time and your great help. I am working on my code with your great help and in case of any question I will post again.

Success!

Best regards,

Tantani






Re: Edit the Recordset

Tantani

Dear Luiz,

Your code snippet works very well, thanks again. Now, I would like to keep the fractions into account as follows:

Quantity
0.50
1.40
0.70
.....

1) Goto first record, check if it is lower than 1, then make it zero BUT keep the number into account.

2) Goto second record, add the fraction number (which it is kept into account) to it and check if the total is more lower than 1, then make it zero; otherwise make it 1.

Do you have any idea on this. I would appreciate you to help me out.





Re: Edit the Recordset

sunzhoujian

It is very good code!

however,

If I have to open one column within the table, then I will look through all those data in this column, what function should I use

1) Movefirst

2) How do I specifically find the column

Thanks a lot in advance!





Re: Edit the Recordset

Tantani

Hi,

If you want to do something with specific column, you can define it as follows:

'To open\define the column
rs.MoveFirst
strNameOfColumn = rs.Fields("NameOfColumn")

'To do something with the column
With rs
.Edit
.Fields("NameOfColumn") = .Fields("NameOfColumn") +-*/ etc.
.Update

rs.MoveNext

' .Edit & .Update can be removed if you dont want to change the value of your records in the column!

Hope this helps!