Looping Logic

philaman01

New Member
Joined
Mar 25, 2005
Messages
6
Hello All...

I need to write some logic so that the database will write new records in succession after each instance.

For example, a user enters 5 records into a spreadsheet and they are saved in the DB as record 1300-1304 respectively. In the next instance, another user adds 5 more records so the DB should write records starting at the next available record (1305). Below you will find my code. Prompt response appreciated. Thanks!

On Error Resume Next

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset

With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source=\\xxxxxxx\documents\xxxxxx\My Documents\Sandbox\Event Management.mdb"
.CursorLocation = adUseClient
.Mode = adModeReadWrite
.Open
End With

rs.Open "Passwords", cn, adOpenDynamic, adLockOptimistic, adCmdTableDirect

Dim intCounter As Integer
Dim intMax As Integer

intMax = 5
intCounter = 0

Do While intCounter < intMax
rs.Fields("Used") = True
Debug.Print rs!recordid & " " & rs!Password & " " & rs!Used
intCounter = intCounter + 1
rs.MoveNext
Loop
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Couldn't you just use an Autonumber?
 
Upvote 0

Forum statistics

Threads
1,221,893
Messages
6,162,662
Members
451,781
Latest member
DylantheD

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top