Need advice with Error Handling for Invalid Path - vba

I could use some advice on how to handle a strange issue that happens to my users.
Issue:
All of my users are on laptops that use VPN to connect to our network. When they disconnect from the VPN and reconnect the network drive also disconnects till they open the drive or folder through file explorer. When this happens and they don't re-establish the connection to the network drive they end up with 3304 error.
Error Handling?
What I'd like to do is setup some sort of error handler to tell them thats what happened with a potential link they could click on to re establish the connection. OR even better just have the VBA code identify that error 3304 has occurred and re-establish the connection automatically for them and no pop up error happen at all.
Has anyone done this? I've done some research but nothing I've found quite fits the criteria for this issue. Looking for any advice or push in the right direction.
I was thinking of something like this where either they get a pop up with a link or skip the pop up all together and find a way to re-connect the drive in the background.
On Error GoTo ErrHandler
'Error Handler
ErrHandler:
If Err.Number = 3304 Then
MsgBox "Error Number:" & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & vbCrLf & _
"This error is due to your VPN being disconnected and reconnected"
Else
End If

We faced that issue a couple months ago. We took the route of actually just showing an informative MsgBox to tell the users what to do to solve by themselves calling a function into the 'Workbook_Open' event that fails if a Central Code for the Company its not found with the Dir() function:
Function IsVPNOn(ByVal strCentralCodePath As String) As Boolean
Dim retBoolean As Boolean
On Error Resume Next
If IsError(Dir(strCentralCodePath & g_strCentralCodeName)) Then
MsgBox "The VPN seems to be disconnected." & vbCr & vbCr & _
"Please check VPN connection if Company toolbar is needed.", _
vbCritical + vbOKOnly, "Company Ribbon"
retBoolean = False
Else
retBoolean = True
End If
IsVPNOn = retBoolean
End Function
Not gonna lie, the second option with skipping and reconnecting without the user being even aware of the problem seems more classy, but it is way trickier as you have to deal with connections inside your code.

Related

trap access vba messages

I'm developing in Access 2007 after a period doing other things and am trying to trap messages to the user. One function in a form modifies a row in a table. The relevant bits of the code are
On Error GoTo PROC_ERR
...
DoCmd.RunSQL szSQL
...
PROC_ERR:
MsgBox "Error: (" & Err.Number & ") " & Err.Description, vbCritical
The SQL statement is correct and he system pops up with a "You are about to update 1 row ..." message (number 10505). I want to trap this and replace it with my own warning message. However, my function doesn't trap an error on this message. Nor does it do so on the message that appears if the user clicks "no": "Run-time error 2501. The RunSQL action was canceled."
In VBA options I have for the moment set Error Trapping to "Break on all errors".
What am I missing here? Have I failed to set some other option in Access?
I would recommend to do not use RunSQL. It requires DoCmd.SetWarnings False, which may affect further warnings in case if it won't be followed by DoCmd.SetWarnings True, for instance after error. Also you won't be able to read quantity of affected rows.
Use
db.Execute szSQL, dbFailOnError
instead, it will allow to trap errors and analyze database state after query execution. Without dbFailOnError option errors won't be raised.
That message is not an error.
You can silent it with
DoCmd.SetWarnings False
Remember to set them on again.

MS access function vba, macro [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm having a small issue while making a report in MS Access. I wrote a function in vba, and created a macro to RunCode (the function). So when I execute the Macro, it runs the function and gives me a message box. See Image..
I've researched this and tried SetWarning OFF but it keeps popping up. How do i get rid of this?
For future reference, a typical "complete" error handling structure looks e.g. like this:
Sub MySub()
On Error GoTo MySub_Err
' Stuff
MySub_Exit:
On Error Resume Next
' ... Stuff that always needs to run on exit can go here ...
' !! This is the important part that prevents the function
' !! from always running into the error handler:
Exit Sub
MySub_Err:
MsgBox Err.Description, vbExclamation, "Runtime Error " & Err.Number & " in MySub"
Resume MySub_Exit
End Sub
MZ-Tools can create this structure automatically (but customizable).
error_handler:
Error_handler:
msgbox err.number & " - " & err.description
this was giving me an error.
I did not do my error_handler: properly (error_handler:). After my function was completed, it would run into error_handler:msgbox err.number & " - " err.description and give me the message box - saying "0 - " because there was no error. I commented it out and everything seems to work okay. Thanks to #HansUp and everyone else for their help.

How to know if I have authorized access to remote pcs

I'm using the code below to retrieve some information from remote pcs. Although I have authorized access to most of the pcs but not all.
I have a list of pc names, and my winforms will read it from there.
So my question is, how do I know if I have authorized access to certain pcs?
Const HKEY_LOCAL_MACHINE = &H80000002
objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & line & "\root\default:StdRegProv")
strISC = "Software\Microsoft\Internet Explorer"
On Error Resume Next
objReg.GetStringValue(HKEY_LOCAL_MACHINE, strISC, "svcKBNumber", strKB)
On Error Resume Next
objReg.GetStringValue(HKEY_LOCAL_MACHINE, strISC, "svcVersion", strsvcVersion)
On Error Resume Next
by the way, I know this is actually in vbscript but I was able to use it in vb.net also.

Runtime Error '3709' while accesing SQL database in VB6

I have a VB6 application which someone wrote, which does not work for only some users who try to use it.
This is the code running which returns an error:
On Error GOTO error_handler
..
Set db = New ADODB.Connection
db.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=****;Password=****; Initial Catalog=***;Data Source=****,1433"
error_handler:
If db.Error.count then
strDBErrors = "No access to Main Database."
For Each err In db.errors
strDBErrors = strDBErrors & vbCrLf & err.Description
Next
MsgBox strDBErrors
After this code runs, I get two Boxes of error. One which states a Runtime Error 3709, And the other which has Two lines: one of it is my Custom error message, and the second if this: "Logon Failed for user the user".
This only happens to one user on a specific computer on which this program is installed. It does not happen on any other computer with any other user.
I tried reinstalling the program with that user on that computer, but it did not work.
Any ideas?
Not quite sure what the problem was,
but I just erased the user on Active Directory and created it again, and it worked.
The user wasn't a member of any deny groups though.

Writing a logon script for different users in VB, needs to be able to map drives. Need some help

What is happening now, is that .bat files are ran on logon, which executes mapping the drives. We now however want to switch these into a VB script. A couple problems, however:
There are 18 drives to map (f through w)
The users aren't group correctly (if at all). I'm probably going to change them into the correct groups, hopefully three different ones so that the script can look that group up and know what to do.
It has to start up a system called LUMINX (not sure if anyone here has ever worked with it. If you have however, i'm sure you know it's from the darkest and depths of hell). Which is set to a certain IP and under LUMINX_LIVE.
I'm QUITE new to coding, and have never really tackled something like this before. I've looked over some codes that would work, however everyone seems to be a bit off and not have something I need.
Any help would be much appreciated.
Code to map a drive with vbscript
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "F:", "\\Server\Folder\Folder"
objNetwork.MapNetworkDrive "G:", "\\Server\Folder2\Folder2"
objNetwork.MapNetworkDrive "H:", "\\Server\Folder3\Folder3"
.......................
objNetwork.MapNetworkDrive "V:", "\\192.x.x.x\luminx_live"
You will need to modify the folder locations but this should work for you. Not sure about the luminx problem (EDIT: included luminx stuff). Is is a service or computer? More details would be helpful
You could use the following code to map drives, however this is modified from bugtussle's code as it give the user an error message if the drive cannot be mapped, this may be useful.
Set wshNetwork = CreateObject( "WScript.Network" )
On Error Resume Next
With wshNetwork
.MapNetworkDrive "G:", "\\CompanyServer\Dept"
If Err Then
WScript.Echo "Error " & Err & " mapping drive G:"
WScript.Echo "(" & Err.Description & ")"
End If
.MapNetworkDrive "H:", "\\CompanyServer\" & .UserName
If Err Then
WScript.Echo "Error " & Err & " mapping drive H:"
WScript.Echo "(" & Err.Description & ")"
End If
End With
On Error Goto 0
Set wshNetwork = Nothing