Captain Frog
New member
- Local time
- Today, 20:00
- Joined
- Dec 14, 2023
- Messages
- 5
Hi
I have a small function that I used many many time to create automatically an error handling whenever I write a new sub or function.
It has been working flawlessly over years, from Access 2 until now. But now, for some reason it does not work anymore.
It uses a form with a text control to copy the template to clipboard.
When I now try to use it, it will fire an error #94 invalid use of null, so I guess it doesn't copy the name of the function as it should. But why?
As I said it worked with access 2, access 10, access 365 until last summer.
Any idea what the reason could be?
Sub CodeTemplate()
'--------------------------------------------------------------
'Purpose :Inser an error trapping code into your sub or function
'Notes lace the caret between the "Function" or "Sub" line and the "End Function" line.
' :and click Makro > CodeTemplate()
' :Needs ZZ_frmTemplate to swap value to the clipboard
'Author :Larroque 06.06.2001
'--------------------------------------------------------------
On Error GoTo Err_CodeTemplate
Dim strMsg As String
Dim strText As String
Dim strName As String
Dim intStart As Integer, intStop As Integer
Dim strType As String
Application.Echo False
SendKeys "{Up 1}" 'place the Sub Name into clipboard
SendKeys "+{End}"
SendKeys "^{INSERT}", True
DoCmd.OpenForm "ZZ_frmTemplate" 'Pass it to the form control
Forms!ZZ_frmTemplate!txtFinal.SetFocus
SendKeys "+{INSERT}", True
SendKeys "{TAB}"
DoEvents 'and to the variable
strName = Forms!ZZ_frmTemplate!txtFinal
DoCmd.Close
If InStr(strName, "Private Sub") Then 'seek the beginning of the sub Name
intStart = InStr(strName, "Private Sub") + 12
intStop = InStr(strName, "(") 'seek the end of the sub Name
strName = Mid$(strName, intStart, intStop - intStart) 'read the name
strType = "Sub"
ElseIf InStr(strName, "Public Sub") Then
intStart = InStr(strName, "Public Sub") + 11
intStop = InStr(strName, "(")
strName = Mid$(strName, intStart, intStop - intStart)
strType = "Sub"
ElseIf InStr(strName, "Sub") Then
intStart = InStr(strName, "Sub") + 4
intStop = InStr(strName, "(")
strName = Mid$(strName, intStart, intStop - intStart)
strType = "Sub"
ElseIf InStr(strName, "Function") Then
intStart = InStr(strName, "Function") + 9
intStop = InStr(strName, "(")
strName = Mid$(strName, intStart, intStop - intStart)
strType = "Function"
End If
strText = "'--------------------------------------------------------------" & vbCrLf
strText = strText & "'Purpose :" & vbCrLf
strText = strText & "'Notes :" & vbCrLf
strText = strText & "'Author : Larroque " & Format(Now, "dd/mm/yyyy") & vbCrLf
strText = strText & "'--------------------------------------------------------------" & vbCrLf
strText = strText & " On Error GoTo Err_" & strName & vbCrLf
strText = strText & " Dim strMsgErr As String" & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf
strText = strText & " Err_" & strName & "_End" & ":" & vbCrLf
strText = strText & " On Error GoTo 0 " & vbCrLf
strText = strText & " Exit " & strType & vbCrLf
strText = strText & " Err_" & strName & ":" & vbCrLf
strText = strText & " strMsgErr = ""Error Information..."" & vbCrLf & vbCrLf" & vbCrLf
strText = strText & " strMsgErr = strMsgErr & """ & strType & ": " & strName & """ & vbCrLf" & vbCrLf
strText = strText & " strMsgErr = strMsgErr & ""Description: "" & Err.Description & vbCrLf" & vbCrLf
strText = strText & " strMsgErr = strMsgErr & ""Error #: "" & Format$(Err.Number) & vbCrLf" & vbCrLf
strText = strText & " Call LogError(strMsgErr)" & vbCrLf
strText = strText & " MsgBox strMsgErr, vbInformation, """ & strName & """ " & vbCrLf
strText = strText & " Resume Err_" & strName & "_End" & vbCrLf
DoCmd.OpenForm "ZZ_frmTemplate"
Forms!ZZ_frmTemplate!txtFinal = strText
Forms!ZZ_frmTemplate!txtFinal.SetFocus
SendKeys "^{INSERT}", True
DoCmd.Close
SendKeys "{DOWN}"
SendKeys "+{INSERT}"
SendKeys "{UP 13}"
SendKeys "{TAB}"
Application.Echo True
Err_CodeTemplate_End:
On Error GoTo 0
Exit Sub
Err_CodeTemplate:
strMsg = "Error Information..." & vbCrLf & vbCrLf
strMsg = strMsg & "Sub: CodeTemplate" & vbCrLf
strMsg = strMsg & "Description: " & Err.Description & vbCrLf
strMsg = strMsg & "Error #: " & Format$(Err.Number) & vbCrLf
' Call LogError(strMsg)
MsgBox strMsg, vbInformation, "CodeTemplate"
Resume Err_CodeTemplate_End
End Sub
I have a small function that I used many many time to create automatically an error handling whenever I write a new sub or function.
It has been working flawlessly over years, from Access 2 until now. But now, for some reason it does not work anymore.
It uses a form with a text control to copy the template to clipboard.
When I now try to use it, it will fire an error #94 invalid use of null, so I guess it doesn't copy the name of the function as it should. But why?
As I said it worked with access 2, access 10, access 365 until last summer.
Any idea what the reason could be?
Sub CodeTemplate()
'--------------------------------------------------------------
'Purpose :Inser an error trapping code into your sub or function
'Notes lace the caret between the "Function" or "Sub" line and the "End Function" line.
' :and click Makro > CodeTemplate()
' :Needs ZZ_frmTemplate to swap value to the clipboard
'Author :Larroque 06.06.2001
'--------------------------------------------------------------
On Error GoTo Err_CodeTemplate
Dim strMsg As String
Dim strText As String
Dim strName As String
Dim intStart As Integer, intStop As Integer
Dim strType As String
Application.Echo False
SendKeys "{Up 1}" 'place the Sub Name into clipboard
SendKeys "+{End}"
SendKeys "^{INSERT}", True
DoCmd.OpenForm "ZZ_frmTemplate" 'Pass it to the form control
Forms!ZZ_frmTemplate!txtFinal.SetFocus
SendKeys "+{INSERT}", True
SendKeys "{TAB}"
DoEvents 'and to the variable
strName = Forms!ZZ_frmTemplate!txtFinal
DoCmd.Close
If InStr(strName, "Private Sub") Then 'seek the beginning of the sub Name
intStart = InStr(strName, "Private Sub") + 12
intStop = InStr(strName, "(") 'seek the end of the sub Name
strName = Mid$(strName, intStart, intStop - intStart) 'read the name
strType = "Sub"
ElseIf InStr(strName, "Public Sub") Then
intStart = InStr(strName, "Public Sub") + 11
intStop = InStr(strName, "(")
strName = Mid$(strName, intStart, intStop - intStart)
strType = "Sub"
ElseIf InStr(strName, "Sub") Then
intStart = InStr(strName, "Sub") + 4
intStop = InStr(strName, "(")
strName = Mid$(strName, intStart, intStop - intStart)
strType = "Sub"
ElseIf InStr(strName, "Function") Then
intStart = InStr(strName, "Function") + 9
intStop = InStr(strName, "(")
strName = Mid$(strName, intStart, intStop - intStart)
strType = "Function"
End If
strText = "'--------------------------------------------------------------" & vbCrLf
strText = strText & "'Purpose :" & vbCrLf
strText = strText & "'Notes :" & vbCrLf
strText = strText & "'Author : Larroque " & Format(Now, "dd/mm/yyyy") & vbCrLf
strText = strText & "'--------------------------------------------------------------" & vbCrLf
strText = strText & " On Error GoTo Err_" & strName & vbCrLf
strText = strText & " Dim strMsgErr As String" & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf
strText = strText & " Err_" & strName & "_End" & ":" & vbCrLf
strText = strText & " On Error GoTo 0 " & vbCrLf
strText = strText & " Exit " & strType & vbCrLf
strText = strText & " Err_" & strName & ":" & vbCrLf
strText = strText & " strMsgErr = ""Error Information..."" & vbCrLf & vbCrLf" & vbCrLf
strText = strText & " strMsgErr = strMsgErr & """ & strType & ": " & strName & """ & vbCrLf" & vbCrLf
strText = strText & " strMsgErr = strMsgErr & ""Description: "" & Err.Description & vbCrLf" & vbCrLf
strText = strText & " strMsgErr = strMsgErr & ""Error #: "" & Format$(Err.Number) & vbCrLf" & vbCrLf
strText = strText & " Call LogError(strMsgErr)" & vbCrLf
strText = strText & " MsgBox strMsgErr, vbInformation, """ & strName & """ " & vbCrLf
strText = strText & " Resume Err_" & strName & "_End" & vbCrLf
DoCmd.OpenForm "ZZ_frmTemplate"
Forms!ZZ_frmTemplate!txtFinal = strText
Forms!ZZ_frmTemplate!txtFinal.SetFocus
SendKeys "^{INSERT}", True
DoCmd.Close
SendKeys "{DOWN}"
SendKeys "+{INSERT}"
SendKeys "{UP 13}"
SendKeys "{TAB}"
Application.Echo True
Err_CodeTemplate_End:
On Error GoTo 0
Exit Sub
Err_CodeTemplate:
strMsg = "Error Information..." & vbCrLf & vbCrLf
strMsg = strMsg & "Sub: CodeTemplate" & vbCrLf
strMsg = strMsg & "Description: " & Err.Description & vbCrLf
strMsg = strMsg & "Error #: " & Format$(Err.Number) & vbCrLf
' Call LogError(strMsg)
MsgBox strMsg, vbInformation, "CodeTemplate"
Resume Err_CodeTemplate_End
End Sub