OK...long time lurker, have used this board as a resource bible for some time - I am not an expert or prolific programmer in VBA but use often for Excel Dev work.
My issue - I am trying to solicit user information prior to saving, I originally used an inputbox top obtain this is information but is not practical (and honestly looks a little unprofessional) as it only always the single line view of text being entered and the text users are entering can easily be 200+ characters.
I created a nice form, declared my public variables to pass info from user form to the before_save module but the variable do not carry between the user form and before_save modules. I have tested outside of the before_save module and code works fine. Here is a sample of what I got:
This code is in "This Workbook"
Public CancelVar As Variant
Public TextReturn As Variant
Public MsgResult1, MsgResult2 As Variant
Public Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Msg1, Msg2 As Variant
Dim Row1 As Integer
On Error Resume Next
' Code for version save
ReqEntry:
Load VersionSaveForm
VersionSaveForm.Show
If MsgResult1 = "admin" Then GoTo SkipEntry
If CancelVar = 7 Then
Cancel = True
Exit Sub
Else: End If
If MsgResult1 = "" Then
MsgResult2 = MsgBox("Notes are required, do you wish to cancel save 'No to cancel' or enter notes 'Yes'?", vbYesNoCancel)
If (MsgResult2 = 7 Or MsgResult2 = 2) Then ' Code to cancel save on user request
Cancel = True
Exit Sub
Else
GoTo ReqEntry
End If
Else
End If
- more code after this, but this is where the issue of not passing variable info back and forth lies. The "VersionSaveForm" has very basic code - a text box where user enters information on the version save, a submit button and a cancel button.
Any help would be greatly appreciated.
Regards,
C
My issue - I am trying to solicit user information prior to saving, I originally used an inputbox top obtain this is information but is not practical (and honestly looks a little unprofessional) as it only always the single line view of text being entered and the text users are entering can easily be 200+ characters.
I created a nice form, declared my public variables to pass info from user form to the before_save module but the variable do not carry between the user form and before_save modules. I have tested outside of the before_save module and code works fine. Here is a sample of what I got:
This code is in "This Workbook"
Public CancelVar As Variant
Public TextReturn As Variant
Public MsgResult1, MsgResult2 As Variant
Public Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Msg1, Msg2 As Variant
Dim Row1 As Integer
On Error Resume Next
' Code for version save
ReqEntry:
Load VersionSaveForm
VersionSaveForm.Show
If MsgResult1 = "admin" Then GoTo SkipEntry
If CancelVar = 7 Then
Cancel = True
Exit Sub
Else: End If
If MsgResult1 = "" Then
MsgResult2 = MsgBox("Notes are required, do you wish to cancel save 'No to cancel' or enter notes 'Yes'?", vbYesNoCancel)
If (MsgResult2 = 7 Or MsgResult2 = 2) Then ' Code to cancel save on user request
Cancel = True
Exit Sub
Else
GoTo ReqEntry
End If
Else
End If
- more code after this, but this is where the issue of not passing variable info back and forth lies. The "VersionSaveForm" has very basic code - a text box where user enters information on the version save, a submit button and a cancel button.
Any help would be greatly appreciated.
Regards,
C