Monday, November 3, 2008

Dynamically Get GP database connection information when using VBA

Dynamically Get GP database connection information when using VBA:

'Class Module: GP Dex_VBA_Link
'Author: Matt Connor
'Version: 2.01
'Updated: 06-Apr-2006

'Connection Properties
Public PasswordUnencrypted As Boolean
Public SQLPassword, SQLPasswordDecoded As String
Public UserID, SQLDataSourceName, RuntimeVersion As String
Public IntercompanyID, CompanyName As String
Public UserDate As Date

Private GP_App As Object
Private GP_Product As Object


Private Sub Get_GP_Info()
'Gets connection properties from dexterity and assigns to class properties
On Error GoTo ErrorHandler
Dim dex As String, dex_error_msg As String, MsgBoxTitle As String
MsgBoxTitle = "Get_GP_Info"
Set GP_App = CreateObject("Dynamics.Application")
GP_App.CurrentProductID = 0
GP_App.SetParamHandler Me
dex = ""
dex = dex & "local boolean Dummy, PasswordUnencrypted; "
dex = dex & "local string SQLPassword, SQLPasswordDecoded; "
dex = dex & "local string UserID, SQLDataSourceName, IntercompanyID, CompanyName, RuntimeVersion; "
dex = dex & "local date UserDate; "
dex = dex & " "
dex = dex & "set UserID to 'User ID' of globals; "
dex = dex & "set PasswordUnencrypted to 'Password Unencrypted' of globals; "
dex = dex & "set SQLPassword to 'SQLPassword' of globals; "
dex = dex & "set SQLPasswordDecoded to Utility_DecodeString(SQLPassword); "
dex = dex & "set IntercompanyID to 'Intercompany ID' of globals; "
dex = dex & "set CompanyName to 'Company Name' of globals; "
dex = dex & "set SQLDataSourceName to 'SQLDataSourceName' of globals; "
dex = dex & "set UserDate to 'User Date' of globals; "
dex = dex & "set RuntimeVersion to Runtime_GetVersionNum(); "
dex = dex & " "
dex = dex & "set Dummy to OLE_SetProperty(""UserID"", UserID); "
dex = dex & "set Dummy to OLE_SetProperty(""PasswordUnencrypted"", str(PasswordUnencrypted)); "
dex = dex & "set Dummy to OLE_SetProperty(""SQLPassword"", SQLPassword); "
dex = dex & "set Dummy to OLE_SetProperty(""SQLPasswordDecoded"", SQLPasswordDecoded); "
dex = dex & "set Dummy to OLE_SetProperty(""IntercompanyID"", IntercompanyID); "
dex = dex & "set Dummy to OLE_SetProperty(""CompanyName"", CompanyName); "
dex = dex & "set Dummy to OLE_SetProperty(""SQLDataSourceName"", SQLDataSourceName); "
dex = dex & "set Dummy to OLE_SetProperty(""RuntimeVersion"", RuntimeVersion); "
dex = dex & "set Dummy to OLE_SetProperty(""UserDate"", str(UserDate)); "
dex_error_msg = ""
GP_App.ExecuteSanscript dex, dex_error_msg
If dex_error_msg <> "" Then
msg = "An unexpected error has occurred running Dexterity script:" & vbCrLf & vbCrLf & dex_error_msg
MsgBox msg, vbCritical, MsgBoxTitle
Exit Sub
End If
Set GP_App = Nothing
Exit Sub
ErrorHandler:
Select Case Err.Number
Case Else
MsgBox "An unexpected error has occurred:" & vbCr & vbCr & Err.Source & vbCr & "Error " & Err.Number & vbCr & Err.Description, vbCritical, MsgBoxTitle
End Select
End Sub

Note: Applicable on versions earlier than GP 10.0.

Regards,
--
Mohammad R. Daoud
MCP, MCBMSP, MCTS, MCBMSS
Software Development Manager
+962 - 79 - 999 65 85
Dynamics Innovations
daoudm@dynamicsinnovations.com
http://www.dynamicsinnovations.com/

No comments:

Related Posts:

Related Posts with Thumbnails