Importing Task

  • Thread starter Thread starter Bre-x
  • Start date Start date
B

Bre-x

Hi,

I have a function on MS Access to export data into outlook
I would like to move to MS Outlook, so that I can importa data

Could you help me to modify it?


Function send_data()
Dim olApp As Outlook.Application
Dim Tsk As Outlook.TaskItem
Dim rst As Recordset

On Error Resume Next

Set olApp = New Outlook.Application

Set rst = CurrentDb.OpenRecordset("SELECT QIT_Tasks.* FROM QIT_Tasks;")
rst.MoveFirst
Do While Not rst.EOF
Set Tsk = olApp.CreateItem(olTaskItem)
With olApp.Application
'-----------------------------------------
Tsk.Subject = rst!tasksubject
Tsk.DueDate = "07/14/2009"
Tsk.Categories = "My Category - Test "
Tsk.Body = "This is the Body - Test" & Chr(10) & "Line 02 -
Test"
Tsk.ReminderTime = "07/13/2009 10:30 AM"
Tsk.ReminderSet = True
Tsk.UnRead = True
Tsk.Save
'-----------------------------------------

DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE IT_Tasks SET status = -1 WHERE
task_id=" & rst!task_id
DoCmd.SetWarnings True
End With

rst.MoveNext
Loop
rst.Close

Set Tsk = Nothing
Set olApp = Nothing

End Function
 
Michael,

Thank you for answering my post
I have modified it, but it gives me an error

Sub Import_Tasks()
'Dim Variables
Dim olApp As Outlook.Application
Dim Tsk As Outlook.TaskItem
Dim var_fields As ADODB.Fields

'OPEN CONNECTION
ConnectDB
Set var_fields = m_Rs.var_fields 'HERE IS THE ERROR (Error: Object
required)

While Not m_Rs.EOF
With olApp.Application
Tsk.Subject = var_fields("tasksubject").Value
Tsk.DueDate = "07/29/2009"
Tsk.Categories = "My Category - Test "
Tsk.Body = "This is the Body - Test" & Chr(10) & "Line 02 - test "
Tsk.ReminderTime = "07/29/2009 10:30 AM"
Tsk.ReminderSet = True
Tsk.UnRead = True
Tsk.Save
End With
m_Rs.MoveNext
Wend

'CLOSE
m_Rs.Clone: Set m_Rs = Nothing
m_Cn.Close: Set m_Cn = Nothing
End Sub

Private Sub ConnectDB()
Dim var_file As String
Dim var_table As String
Dim var_fields As String

var_file = "E:\Programing\MSACCESS\Outlook_VBA\it_tasks.mdb"
var_table = "QIT_Tasks"
var_fields = "tasksubject, task_id"


Set m_Cn = New ADODB.Connection
With m_Cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = var_file
.CursorLocation = adUseClient
.Mode = adModeShareDenyNone
.Open
End With

Set m_Rs = New ADODB.Recordset
With m_Rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
Set .ActiveConnection = m_Cn
.Open ("SELECT " & var_fields & " FROM " & var_table)
End With
End Sub
 
I'm sorry, that's my fault. On the module level you need to declare the
variables:

Private m_Rs as Adodb.Recordset
Private m_Cn as Adodb.Connection

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 29 Jul 2009 14:14:28 -0600 schrieb Bre-x:
 
Back
Top