| re: Basic "For... To... Loop" question
This seems to be working:
Public Sub Import()
On Error GoTo HandleErr
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblAppointments")
Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.AppointmentItem
Dim objItems As Outlook.Items
Dim varAppt As Variant
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderCalendar)
Set objItems = cf.Items
For Each varAppt In cf.Items
If varAppt.Location <> "United States" And varAppt.Start > Date - 1
Then
rst.AddNew
rst!Location = varAppt.Location
rst!Date = varAppt.Start
rst!Subject = varAppt.Subject
rst.Update
End If
Next
rst.Close
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case Else
MsgBox "Error Number " & Err.Number & ": " & Err.Description
Resume Exit_Here
End Select
End Sub
"deko" <dje422@hotmail.com> wrote in message
news:NacAb.33214$FA.25250@newssvr29.news.prodigy.c om...[color=blue]
> This sub pulls Outlook Appointments into a table.
>
> The problem is I want to limit the import to Location = Boston
>
> I'm not sure how to code that into the For... To loop - As it is now, I[/color]
get[color=blue]
> the following error:
>
> Run-time error '3163':
> The field is too small to accept the amount of data you attempted to add.
> Try inserting less data.
>
> Any suggestions very welcome!!! Thanks in advance...
>
> Public Sub Import()
> Dim rst As DAO.Recordset
> Set rst = CurrentDb.OpenRecordset("tblAppointments")
> Dim ol As New Outlook.Application
> Dim olns As Outlook.Namespace
> Dim cf As Outlook.MAPIFolder
> Dim c As Outlook.AppointmentItem
> Dim objItems As Outlook.Items
> Dim Prop As Outlook.UserProperty
> Dim iNumApts As Integer
> Dim i As Integer
> Dim lngEid As Long
> Set olns = ol.GetNamespace("MAPI")
> Set cf = olns.GetDefaultFolder(olFolderCalendar)
> Set objItems = cf.Items
> iNumApts = objItems.Count
> If iNumApts <> 0 Then
> For i = 1 To iNumApts
> If TypeName(objItems(i)) = "AppointmentItem" Then
> Set c = objItems(i)
> If c.Location = Boston Then
> rst.AddNew
> rst!Location = c.Location
> rst!Date = c.Start
> rst!Subject = c.Subject
> rst.Update
> End If
> End If
> Next i
> rst.Close
> End If
> End Sub
>
>[/color] |