By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

expertatexcel.com

 


Popup - udf


Sub Popup(sMsg As String, Optional computer)
'This routine will insert a record in the db that will cause a popup message to appear at the specified machine.
'If no computer is passed then some default  machine is used.  User must run the Popup software
Dim sSQL As StringS
Dim x
Dim svDB As String
Dim bReopen As Boolean

If IsMissing(computer) Then
    computer = GetSystemVar("popup_pc", "DefaultMachineNamegoeshere")
End If

If ComputerName = computer Then
    'It's running on my machine so don't popup
    Exit Sub
End If


sSQL = "Insert fusiondaily.popup_t (computer,date,popup,user) values('" & computer & "','" & Format(Now(), "yyyy-mm-dd hh:mm:ss") & "','" & ThisWorkbook.Name & " - " & QF(sMsg) & "','" & Application.UserName & "')"
On Error Resume Next
If gI2ado Is Nothing Then
    Set gI2ado = GetConnection()
End If

'svDB = gI2ADO.Properties(9) '@todo: got err 91 here
svDB = gI2ado.Properties(86) 'Connection
If Err <> 0 Then
    AppMsgbox Err & " " & Error
    
    Exit Sub
End If

'If gI2ADO.Properties(9) = "Johns Risk Factors" Then
'If gI2ADO.Properties(11) = "MySQL" Then
'    gI2ADO.Close
'    Set gI2ADO = Nothing
'
'    Set gI2ADO = GetConnection("Johns Risk Factors")
'    bReopen = True
'End If


x = RunQuery(sSQL, , , gI2ado)
If InStr(x, "[") > 0 Then
    
    AppMsgbox x & vbCrLf & sSQL
    Email GetSystemVar("main_support_email", "Al@cherper.com"), ThisWorkbook.Name & "@" & GetSystemVar("company_domain", "XYZCapital.com"), "", "Popup routine can't write to db", x & vbCrLf & sSQL, "", False
End If

'If svDB = "Erans Risk Factors" Then
If bReopen Then
    gI2ado.Close
    Set gI2ado = Nothing
    Set gI2ado = GetConnection(svDB)
End If

End Sub