Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Looping through code for every record in a table

Hi,

I have a table with 2 fields - flddate and category. There are 999
records in the table. Currently I use the below code to create an
outlook appointment from one of the records in the table. However I
would like to loop through each of the records to create an outlook
appointment for each of the records. I guess I need to create an ID
for each record and loop through the reocrd numbers but I don't know
where to start.

Private Sub Command6_Click()
DoCmd.Save
Dim objFolder As MAPIFolder
Dim spobj As Variant
Set spobj = CreateObject("Outlook.Application")
Dim outobj As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Set outobj = CreateObject("outlook.application")
Set objAppt = outobj.CreateItem(olAppointmentItem)
With objAppt
objAppt.Start = [fldDate]
objAppt.AllDayEvent = True
.Subject = category
.ReminderSet = False
.Save
DoCmd.RunCommand acCmdSaveRecord
End With
End Sub

Thanks,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 222
Default Looping through code for every record in a table

No need for anything additional, have a look at looping in the help file.
Basically, you can create a loop such as:-

For c = 1 to 999
Cells(c,1).Select
<-- do your stuff here --
Next

"keri" wrote:

Hi,

I have a table with 2 fields - flddate and category. There are 999
records in the table. Currently I use the below code to create an
outlook appointment from one of the records in the table. However I
would like to loop through each of the records to create an outlook
appointment for each of the records. I guess I need to create an ID
for each record and loop through the reocrd numbers but I don't know
where to start.

Private Sub Command6_Click()
DoCmd.Save
Dim objFolder As MAPIFolder
Dim spobj As Variant
Set spobj = CreateObject("Outlook.Application")
Dim outobj As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Set outobj = CreateObject("outlook.application")
Set objAppt = outobj.CreateItem(olAppointmentItem)
With objAppt
objAppt.Start = [fldDate]
objAppt.AllDayEvent = True
.Subject = category
.ReminderSet = False
.Save
DoCmd.RunCommand acCmdSaveRecord
End With
End Sub

Thanks,


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Looping through code for every record in a table

Keri,
That code looks like you're working from Access, not Excel? Am I correct?
If I am not, then do 2 things:
Let me know,
Ignore what I'm about to write.

To loop through records in a recordset in Access, you can do something like
this:

Sub SaveRecordsAsAppointments()
Dim myDB as DAO.Database
Dim myRST as DAO.Recordset
Dim RecordLoop as Long
Set myDB = LocalDB
Set myRST = myDB.OpenRecordset("name of your table or query")
'... your existing declarations here also
'...all the way down to the With objAppt

myRST.MoveLast
myRST.MoveFirst
For RecordLoop = 1 to myRST.RecordCount
With objAppt
'.... will pickup current record info
'.... and make appointment from it
'....
' no need to Save the Record as that's
' already saved in Access, presumably
End With
myRST.MoveNext ' loop to next Access Record
Next ' RecordLoop
myRST.Close
Set myRST = Nothing
myDB.Close
Set myDB = Nothing

End Sub
"keri" wrote:

Hi,

I have a table with 2 fields - flddate and category. There are 999
records in the table. Currently I use the below code to create an
outlook appointment from one of the records in the table. However I
would like to loop through each of the records to create an outlook
appointment for each of the records. I guess I need to create an ID
for each record and loop through the reocrd numbers but I don't know
where to start.

Private Sub Command6_Click()
DoCmd.Save
Dim objFolder As MAPIFolder
Dim spobj As Variant
Set spobj = CreateObject("Outlook.Application")
Dim outobj As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Set outobj = CreateObject("outlook.application")
Set objAppt = outobj.CreateItem(olAppointmentItem)
With objAppt
objAppt.Start = [fldDate]
objAppt.AllDayEvent = True
.Subject = category
.ReminderSet = False
.Save
DoCmd.RunCommand acCmdSaveRecord
End With
End Sub

Thanks,


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code looping through files Otto Moehrbach Excel Programming 66 January 5th 07 07:46 PM
Help with Looping Code JimMay Excel Programming 5 June 6th 06 03:43 AM
stopping code from looping tjb Excel Worksheet Functions 3 December 7th 05 02:02 AM
Looping macros using VB code accessuser1308 Excel Discussion (Misc queries) 2 March 9th 05 11:11 PM
Code looping when it should not Todd Huttenstine Excel Programming 3 May 13th 04 09:37 PM


All times are GMT +1. The time now is 11:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"