how i can run this code with all records

free2000000

New member
Local time
Yesterday, 22:12
Joined
Aug 31, 2011
Messages
2
hello evry body

how are you? I hope you ara fine and have a great time.

I have this code in Button in a form based in runtime table access 2003

----------------------------------------------------------
Dim khaher As Object
Set khaher = CurrentDb.OpenRecordset("Employment")
With khaher
If MsgBox("do you wont to save?" & vbCrLf & "", vbYesNo, "Update") = vbYes Then
khaher.AddNew
khaher!vessel = Me.Combo44.Value
khaher!Syndicate = Me.Combo57.Value
khaher!seaman = Me.filed.Value
.Update
.Close
----------------------------------------------------------------------------------
its work ok , but it just add the data from the first record . I want to re run the code to add all records from the run time table
thank you
 
You can do the recordset stuff inside a loop.

ex:

Code:
Dim rs As DAO.Recordset
Set rs = Currentdb.OpenRecordset("....")
If rs.Recordcount > 0 Then
   rs.Move.First
   DoUntil rs.EOF
      ' do stuff
   rs.MoveNext
   Loop
End If

However it is more efficient to do bulk insert using a query or execute a querystring.

ex:

Code:
Currentdb.Execute "Insert Into ....", dbFailOnError

JR
 
Last edited:
Private Sub ÃãÑ32_Click()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("....")
If rs.RecordCount > 0 Then
rs.MoveFirst
Do Until rs.EOF
' do stuff
If MsgBox("åá ÊÑíÏ ÊÓÌíá Úãá äÞÇÈÉ" & vbCrLf & "", vbYesNo, "ÊÍÏíË") = vbYes Then
Dim db As Database
Dim rss As Recordset
Set db = CurrentDb
Set rss = db.OpenRecordset("Employment")
rss.AddNew
rss!seaman = Me.ÇÓã_ÇáÈÍÑí.Value
rss!vessel = Me.Combo44.Value
rss!Syndicate = Combo57.Value
rss.Update
rss.Close
Set rss = Nothing
Set db = Nothing
Loop
End If
End Sub

it gaves me errors
 
Set rs = CurrentDb.OpenRecordset("....")


this section, you must specify the form's source table or query..


Set rs = CurrentDb.OpenRecordset("table_name")

as...
 
it gaves me errors

No kidding:rolleyes:

You can't just cut and paste and hope examplecode it will work. I just gave you a look on how a recordset loop looks like althou I forgot to move the recordset pointer before the loop statement. I have some trouble with this statement:

I want to re run the code to add all records from the run time table

What is the runtime table is it a temorary table in your database that you store your data and then move this data over to your Employment table??

It sounds rather Unnormalized to do so, I would just bind the form you use to the table and validate entries before moving to the next record.

This is how I would code a batch data move between 2 tables:
Code:
Dim khaher As DAO.Recordset
Dim rs As DAO.Recordset
Set khaher = CurrentDb.OpenRecordset("Employment")

If MsgBox("do you wont to save?" & vbCrLf & "", vbYesNo, "Update") = vbYes Then
   Set rs = Currentdb.OpenRecordset("[COLOR="Red"]NameOfYourRuntimeTable[/COLOR]")  '<----????
       If rs.RecordCount > 0 Then
          rs.MoveFirst
          DoUntil rs.EOF
	      With khaher
		.AddNew
		!vessel = rs![COLOR="red"]Whatever[/COLOR]
		!Syndicate = rs![COLOR="red"]whatever2[/COLOR]
		!seaman = rs![COLOR="red"]Whatever3[/COLOR]
		.Update
	      End With
           rs.MoveNext   '<--- Move pointer
	   Loop
	   rs.Close
           khaher.Close
       End If
End If

Anything marked in red must match your setup. Hope this makes things clearer.

JR
 

Users who are viewing this thread

Back
Top Bottom