Kamis, 14 Juli 2011

Re: [MS_AccessPros] Outlook 2007 VBA events to Access table field

As long as you're comfortable with running sql from code, yes.

You'd need to establish a connection to the access database in your code -
http://www.connectionstrings.com/ is a great resource for figuring out which
connection string to use.


~~~~~~~~~~ Sample code below ~~~~~~~~~~~
Private Function UpdateMyTable() As Boolean
' requires reference to: Microsoft ActiveX Data Objects 2.8 or higher
' returns FALSE if function SNAFU'd or TRUE if it went through

On Error GoTo ErrHandler

Dim cn As ADODB.Connection
Dim strSQL As String
Dim strCon As String
Dim strDB As String

' give the full database file name with path here
strDB = "C:\MyPath\MyDatabase.accdb"

' modify SQL for your purposes
strSQL = "INSERT INTO [table] ( [fields] ) VALUES ( [values] );"
' strSQL = "UPDATE [table] SET [field] = [value] WHERE [condition];"

' connection string here
strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & _
strDB & ";Persist Security Info=False;"

Set cn = New ADODB.Connection

With cn
.Open strCon
.Execute (strSQL)
End With

UpdateMyTable = True

Exit_ErrHandler:
cn.Close
Set cn = Nothing
Exit Function

ErrHandler:
UpdateMyTable = False
MsgBox "Oops!" & vbCrLf & Err.Number & ": " & _
Err.Description, vbCritical + vbOKOnly, "Error!"
Resume Exit_ErrHandler

End Function

Regards,

Shay Buchanan


On Wed, Jul 13, 2011 at 1:30 PM, Liz Ravenwood <
liz_ravenwood@beaerospace.com> wrote:

> **
>
>
> Pros, is it possible to write VBA in Outlook 2007 that upon completion of a
> task it alters an Access table field value?
> This email (and all attachments) is for the sole use of the intended
> recipient(s) and may contain privileged and/or proprietary information. Any
> unauthorized review, use, disclosure or distribution is prohibited. If you
> are not the intended recipient, please contact the sender by reply e-mail
> and destroy all copies of the original message.
>
>
>


[Non-text portions of this message have been removed]

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/MS_Access_Professionals/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/MS_Access_Professionals/join
(Yahoo! ID required)

<*> To change settings via email:
MS_Access_Professionals-digest@yahoogroups.com
MS_Access_Professionals-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
MS_Access_Professionals-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/

Tidak ada komentar:

Posting Komentar