Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook fields to Access fields

Status
Not open for further replies.

gobjob

Programmer
Mar 11, 2003
4
US
I am trying to write the Outlook user defined fields to an access database. I have been successful in having this work with one exception. I have a series of user defined currency fields. I specify these as currency in Access. The first time I try to add or update a record, no problem. The second time I try to save a record (which will then call the add or update routine) Outlook shuts down. If I change the currency field in Access to a text field, there is no problem but the currency data is not usable as a number. The same holds true if you use a number field. Has anyone experienced this or can anyone help?
 
You're going to need to post your script.

Are you saying you write the values to Access and Outlook shuts down? or are writing the values to Access and then writing them back to Outlook?

Also, from where is the script being hosted/run, from an Outlook form, .VBS file, or what? Jon Hawkins
 
I am trying to go from Outlook to Access on 2000 on Office Professional 2000. I have selected DAO 36 and OLE Automation along iwth 9.0 of Outlook and Access as the book shows. Here is the code I am using. It is in VBScript.

The code is working. Outlook is writing perfectly to Access as long as the Access fields are text and not currency. If I make the Access fields currency that match fields in Outlook that are currency, I am allowed to write the first record without any problems. But then after that when you attempt to save anything. Outlook crashes with a Exception error c0000005 (access violation) Function: fault at 1b04d13e. The same thing happens in Windows XP.

I hope I haven't forgot anything.

Thanks.

'**********************************************************
'Procedure: Item_Write()
'Description: If the item is new, then the AddNewDatabaseRecord procedure is called.
' If the item record is in the database, the UpdateDatabaseRecord procedure is
' called if the field values have change. (ItemChanged = True)
'**********************************************************

Function Item_Write()
Call CheckPercent
If Item.UserProperties.Find("Database Record Created").Value = "No" then
Call AddNewDatabaseRecord ()
Item.UserProperties.Find("Database Record Created") = "Yes"
Else
If ItemChanged = True then
Call UpdateDatabaseRecord ()
End if
End if
End Function

'***********************************************************
'Procedure: AddNewDatabaseRecord
'Description: Adds a new record to the Purchase Database
'***********************************************************
Sub AddNewDatabaseRecord ()
DbOpenTable = 1
On Error Resume Next
Set Dbe = Item.Application.CreateObject("DAO.DBEngine.36")
If Err.Number <> 0 then
Msgbox Err.Description & &quot; -- Some functions may not work correctly&quot;& chr(13) & &quot;Contact your folder administrator to make sure you have DAO 3.6 installed on this machine.&quot;
Exit Sub
end if
Set myDB = Dbe.Workspaces(0).OpenDatabase(&quot;F:\OUTLOOK Templates and Databases\Purchase.mdb&quot;)
Set Rs = MyDB.OpenRecordSet(&quot;Purchase&quot;, DbOpenTable)
Rs.AddNew
Rs(&quot;Status&quot;)=Item.Status
Call FieldValues
Rs.Update
Rs.MoveLast
Rs.close
MyDB.close
End Sub

'***********************************************************
'Procedure: UpdateDatabaseRecord
'Description: Updates an existing record in the Purchase database.
'***********************************************************
Sub UpdateDatabaseRecord ()
DBOpenTable = 1
On Error Resume Next
Set Dbe = Item.Application.CreateObject(&quot;DAO.DBEngine.36&quot;)
If Err.Number <> 0 then
Msgbox Err.Description & &quot; -- Some functions may not work correctly&quot; & &quot;Contact your folder administrator to make sure you have DAO 3.6 installed on this machine.&quot;
Exit Sub
End if
Set MyDB = Dbe.Workspaces(0).OpenDatabase(&quot;F:\OUTLOOK Templates and Databases\Purchase.mdb&quot;)
Set Rs = MyDB.OpenRecordset (&quot;Purchase&quot;, DBOpenTable)
Rs.Index = &quot;Document ID&quot; 'Define current index
Rs.Seek &quot;=&quot;, item.UserProperties.Find(&quot;Document ID&quot;).Value
msgbox &quot;The database has been updated.&quot;
Rs.Edit
Rs(&quot;Status&quot;)=Item.Status
Call FieldValues
RS.Update
Rs.MoveLast
Rs.Close
MyDB.Close
End sub

'***********************************************************
'Procedure: FieldValues
'Description: Calls the CheckValue function and passes it the name of the form field
' and the database field.
'***********************************************************
Sub FieldValues ()
On Error Resume Next
CheckValue &quot;Document ID&quot;, &quot;Document ID&quot;
CheckValue &quot;(1) Requested by&quot;, &quot;Requester&quot;
CheckValue &quot;Element&quot;, &quot;Element&quot;
CheckValue &quot;(14) Plan Name/Prog&quot;, &quot;Plan&quot;
CheckValue &quot;(15) Account&quot;, &quot;Account&quot;
CheckValue &quot;Order Number&quot;, &quot;TEO Number&quot;
CheckValue &quot;Completion Date&quot;, &quot;Completion Date&quot;
CheckValue &quot;Year&quot;, &quot;Year&quot;
CheckValue &quot;Ship Date&quot;, &quot;Ship Date&quot;
CheckValue &quot;Total Capital&quot;, &quot;Total Capital&quot;
CheckValue &quot;Total Expense&quot;, &quot;Total Expense&quot;
CheckValue &quot;Total Softcap&quot;, &quot;Total Softcap&quot;
CheckValue &quot;Total Project&quot;, &quot;Total Project&quot;
CheckValue &quot;Plan Name 1&quot;, &quot;1Plan&quot;
CheckValue &quot;1 Total Capital&quot;, &quot;1Capital&quot;
CheckValue &quot;1 Total Expense&quot;, &quot;1Expense&quot;
CheckValue &quot;1 Total Softcap&quot;, &quot;1Softcap&quot;
CheckValue &quot;Plan Name 2&quot;, &quot;2Plan&quot;
CheckValue &quot;2 Total Capital&quot;, &quot;2Capital&quot;
CheckValue &quot;2 Total Expense&quot;, &quot;2Expense&quot;
CheckValue &quot;2 Total Softcap&quot;, &quot;2Softcap&quot;
CheckValue &quot;Plan Name 3&quot;, &quot;3Plan&quot;
CheckValue &quot;3 Total Capital&quot;, &quot;3Capital&quot;
CheckValue &quot;3 Total Expense&quot;, &quot;3Expense&quot;
CheckValue &quot;3 Total Softcap&quot;, &quot;3Softcap&quot;
CheckValue &quot;TEO Completed&quot;, &quot;TEO Completed&quot;
CheckValue &quot;Status - Order&quot;, &quot;Status&quot;
CheckValue &quot;Total Plan 1&quot;, &quot;Total Plan 1&quot;
CheckValue &quot;Total Plan 2&quot;, &quot;Total Plan 2&quot;
CheckValue &quot;Total Plan 3&quot;, &quot;Total Plan 3&quot;
CheckValue &quot;Transfer Needed&quot;, &quot;Transfer&quot;
CheckValue &quot;Number&quot;, &quot;Number&quot;
End Sub

'***********************************************************
'Procedure: CheckValue
'Description: Checks the field for valid data. If valid data exists, writes
' the field value to the database.
'***********************************************************
Sub CheckValue (ByVal FormField, ByVal DbField)
If Not UserProperties.Find(FormField) is Nothing then
If UserProperties.Find(FormField).Value <> &quot;&quot; then
If IsDate(UserProperties.Find(FormField).Value) then
If userProperties.Find(FormField).Value <> &quot;1/1/4501&quot; then
Rs(DbField) = UserProperties.Find(FormField).Value
else
Rs(DbField) = Null
end if
else
Rs(DbField) = UserProperties.Find(FormField).Value
end if
end if
end if
end sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top