How do I define an event handler for an OptionGroup in VBA-compatible Sax Basic Engine? - vba

I have the following OptionGroup defined in dialog in VBA compatible Sax Basic Engine (embedded for scripting in the localization application Passolo):
Sub Main
.
.
Begin Dialog UserDialog 690,404,"Export and Import Text Files" ' %GRID:10,7,1,1
.
.
OptionGroup .ExportImport
OptionButton 30,77,190,14,"Export for translation",.optExport
OptionButton 20,221,190,14,"Import translations",.optImport
I would like to assign an event handler to capture the change in selection so that I can enable/disable some other controls in the dialog depending on the current selection.
How do I define an event handler for an OptionGroup? Should it be defined at OptionGroup-level or at OptionButton-level (i.e. one event handler for each radio button)?

In Sax Basic/WinWrap Basic the closest thing to an event handler that I am aware of is the (dialogfunc) prototype. Your implementation should handle changes to OptionGroup values in case 2: the top radio button will have SuppValue 0.
The dialogfunc in the example below will output text to the Passolo Messages window when you select a radio button:
Sub Main
Begin Dialog UserDialog 690,404, "Export and Import Text Files",.ExpImpDlgFunct
OptionGroup .ExportImport
OptionButton 30,77,190,14,"Export for translation",.optExport
OptionButton 30,221,190,14,"Import translations",.optImport
OKButton 30,280,60,20
End Dialog
Dim dlg As UserDialog
Dialog dlg
End Sub
Private Function ExpImpDlgFunct(DlgItem$, Action%, SuppValue&) As Boolean
Select Case Action%
Case 1 ' Dialog box initialization
Case 2 ' Value changing or button pressed
If DlgItem = "ExportImport" Then
Select Case SuppValue
Case 0:
PSL.Output("Export")
Case 1:
PSL.Output("Import")
End Select
End If
Rem DlgFunc = True ' Prevent button press from closing the dialog box
Case 3 ' TextBox or ComboBox text changed
Case 4 ' Focus changed
Case 5 ' Idle
Rem DlgFunc = True ' Continue getting idle actions
Case 6 ' Function key
End Select
End Function
You can find additional examples of dialogfuncs here and here.

Related

How do I change the _Click() event on a MS Access Form?

I am hoping to be able to streamline my UI. I want to have a set of command buttons change the _On_Click() event based on a user selection. For example:
Main topic selections: cmd1:"Membership Reports", cmd2: "Administration Reports", cmd3: "Other Reports - TBD"
If the user selects cmd1 then the subtopic buttons properties change to allow the user to open reports in that category.
Sub Topic Selections: cmd4: "All Members", cmd5: "Active Members", etc.
If the user selects cmd2: then the on_Click event would change to open reports in the "Administration Reports" group.
Thanks in advance for your help.
I would use 3 main Toggle Buttons and put hem into an Option group frame (Let's call it FrameMain). Set the Option Value for the buttons as 1,2,3. Create as many regular buttons a you have sub topics (let's call them cmd1_1, cmd1_2, cmd2_1....) and set theirs property Visible to False and Tag to Sub. Now create event FrameMain_AfterUpdate:
Private Sub FrameMain_AfterUpdate()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "Sub" Then
ctl.Visible = False
End If
Next
Select Case Me.FrameMain
Case 1
cmd1_1.Visible = True
cmd1_2.Visible = True
Case 2
cmd2_1.Visible = True
cmd2_2.Visible = True
Case 3
cmd3_1.Visible = True
cmd3_2.Visible = True
End Select
End Sub
You can create now On_Click() event for all your sub-buttons to open the report you want.
You can also use a Switch board (search the Internet how to create it).

DocumentBeforePrint does not fire for Envelope print for VBA in Word

I am trying to switch users to use a different printer for envelopes in Word. If they create the envelope, then print it, it works great using DocumentBeforePrint. However, this event is NOT fired when using the Print button on the dialog Mailings --> Envelopes. Is there any event fired when this happens that I can catch?
thanks,
Mike
There is no event, as such, however...
It is possible to Display, Execute or Show Word's built-in dialog boxes. A number of the controls in these dialog boxes are exposed so that they can be set or read. And the button used to dismiss the dialog box returns a value that can be evaluated.
The list of exposed controls is documented here. The WdWordDialog enumerator for envelopes is wdDialogToolsCreateEnvelope. The properties listed are for both envelopes and labels, keep that in mind when sorting through the possibilities. Note that there is no IntelliSense for these properties. (For .NET people reading this, the properties are accessed via late-binding, meaning C# must use PInvoke in order to work with them.)
To read the user's input, place the properties after the method; to make "default setting", place the properties before the method.
Dismissing this dialog box returns the following values:
0 Cancel (or the "X" button)
1 Print
2 Add to Document:
Since you need to do something before the print job is sent, you probably need to use Display rather than Show. Display does not execute the dialog box when the user dismisses it. Instead, it's necessary to capture the settings, do something with them, then Execute the the dialog box.
For example, the following code displays the dialog box to the user, capture's the delivery address typed into that box, then handles the various return values.
Sub PrintEnvelopes()
Dim dlg As Word.Dialog
Dim retVal As Long
Dim recipAddress As String
Set dlg = Application.Dialogs(wdDialogToolsCreateEnvelope)
With dlg
retVal = .Display
recipAddress = .envaddress
End With
Select Case retVal
Case 1 'Print
With dlg
'Change the printer here
.envaddress = recipAddress
.Execute
End With
Case 0 'Cancel
Case 2 'Add to document
With dlg
.envaddress = recipAddress
.Execute
End With
End Select
End Sub
Turns out, there are events you can place in a module to intercept the Envelope tool launch (h/t http://www.gmayor.com/fax_from_word.htm). As such, I added the following to one of my modules, and it runs when Mailings-->Envelopes is selected, so I can switch the printer, load the dialog, then switch the printer back after the dialog is finished:
Sub ToolsCreateEnvelope()
Dim DoChangePrinter As Boolean
Dim OriginalPrinterName As String
DoChangePrinter = False
OriginalPrinterName = Application.ActivePrinter
CurrentPrinterName = OriginalPrinterName
//Change to use color if on B&W printer
If InStr(1, LCase(CurrentPrinterName), "b&w") Then
CurrentPrinterName = Replace(CurrentPrinterName, "B&W", "COLOR")
DoChangePrinter = True
End If
If (DoChangePrinter) Then ChangePrinter
Application.ActiveDocument.Envelope.DefaultOmitReturnAddress = True
//Show dialog
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogToolsCreateEnvelope)
With oDlg 'Pop up the envelopes dialog
.extractaddress = True
.Show
End With
ActivePrinter = OriginalPrinterName 'Restore the original printer
End Sub

VBA - Closing the Opened form by DblClick Event, closes the whole running code?

I have a userform and some textboxes, I created a DblClick event to open and fill the second form according to the text box data. The problem is when I close Userform4, the whole running forms disappear! Nothing happens when I close userform3. But still, the mouse pointer shows the round status, like it is running a code!
I tried to change the Query_Close event of the second form to hide, but no luck. Can you please help? There is no Cancel button the Second form.
Private Sub txt1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If Txt1.Locked = True Then
With ThisWorkbook.Sheets("target").Range("a1")
UserForm4.TextBoxJob2 = Txt1.value
UserForm4.TextBoxBadgeNum2 = .Offset(RowNumber, 3)
UserForm4.ComboBoxAC2 = .Offset(RowNumber, 0)
UserForm4.Show
End With
Else
UserForm3.Show
End If
End Sub
Regards,
M

MS Access 2013, Subform operations destroy the class module

I have a form in my Access project called MainForm, there is a sub form called subForm, also many buttons on the MainForm, at the same time, I created a class module to handle the OnClick event for all the buttons and the module name is classButtons.
Code in the class module:
Public WithEvents cButtons as Access.CommandButton
Dim tmpValue as String
Private Sub cButtons_Click()
Select Case cButton.Name
Case "ButtonA"
MainForm.subForm.Requery
Case "ButtonB"
Let tmpValue = subForm.ComboBox1.Value
DoCmd.RunSQL "update sometable set somefield='" & tmpValue & "'"
Case "ButtonC"
DoCmd.RunCommand acCmdUnhideColumns
End Select
End Sub
In the Open event of the MainForm, I have the following code:
For i = 0 to Me.Controls.Count - 1
If Left(Me.Controls(i).Name,6) = "cmdbtn" Then
set btnClass = New classButtons
set btnClass.cButtons = Me.Controls(i)
btnClass.cButtons.OnClick = "[Event Procedure]"
mdPublic.buttonColl.Add btnClass 'buttonColl is a collection variable declared in another module called "mdPublic"
End If
Next
Then once the MainForm is opened, all the 3 buttons works well, but once ButtonA or ButtonB is clicked, all the 3 buttons will stop working.
I tried to remove the subForm operations from ButtonA and ButtonB, and found that the problem is disappeared, so I guess the subForm operations just "destroy" the class module.
But I do need those operations, anyone has any ideas? Thank you !!!!!
What I do is make a function behind the form to handle the button behaviors, call it HandleButtonClick(x As String), then in each button Click event property:
=HandleButtonClick("ButtonA") -- change the button designation as appropriate
Also, I always name a subform container different from the subform it holds, such as ctrDetails. Code behind main form must reference the subform container name.

Opening new form after right click on selected record in continuous form

In my access database before I was using a list box in the form for having list of items and I had below code for opening new form after right click on each selected item in list box.
Private Sub ItemList_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Const RIGHTBUTTON = 2
If Button = RIGHTBUTTON Then
DoCmd.OpenForm "frmShortcut_GenerateTask"
DoCmd.MoveSize udtPos.X * mp.TwipsPerPixelX, udtPos.Y * mp.TwipsPerPixelY
End If
End Sub
Now I am using a continuous form instead of list box and I have defined a [isselected) field for selecting each record in continuous form after clicking on that. Now my problem is how I have to write code for right clicking and opening new form.
I used the same code I had used for list box, but it does not work and nothing happened.
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Const RIGHTBUTTON = 2
If Button = RIGHTBUTTON Then
DoCmd.OpenForm "frmShortcut_GenerateTask"
DoCmd.MoveSize udtPos.X * mp.TwipsPerPixelX, udtPos.Y * mp.TwipsPerPixelY
End If
End Sub
Private Sub P_Click()
On Error Resume Next
Me.IsSelected = Not Me.IsSelected
' Save the status
Me.Dirty = False
' Force conditional highlighting
P_ForceHighLight
' Update display in SF_Selected
Me.Parent("SF_Selected").Requery
ActiveControl.SelLength = 0
On Error GoTo 0
End Sub
I recommend either using a DoubleClick event in all of your textboxes and combos, or else putting a small button at one edge of your continuous form that allows the user to open records. Right-click is going to give you problems (so will labels and image controls) because this event doesn't cause (or ensure) that the Form's internal Recordset Bookmark property is actually moved to the record they right-clicked on. In my experience, only buttons, textboxes, and comboboxes will move the Bookmark to the record the user is trying to select.
To Test this, try putting code at the top of your different routines that shows you what record is selected:
MsgBox "RecordID = " & Me!RecordIDField
If you are consistently getting the correct ID, then your problem has to do with how your opening your new form, passing parameters or arguments, etc.