tfield.onchange not fired when we reset tfield to oldvalue - onchange

the Event tfield.onChange is fired when we update a record but not fired when we reset it to oldvalue ( ex cancelUpdates or simply cancel ) . Can we change this behavior?

Related

How to find what caused an event? VB.Net

I have a Handler for a ComboBox.SelectedIndexChanged event. The 'sender' tells me that it is the ComboBox that caused the event, and what its text and value currently is, but what I need to find out is what caused the ComboBox to change its selection in the first place?
How do I find out which line in my program is causing the ComboBox to change, please?
I added the following code to my Handler, and found some useful clues:
Dim st As New StackTrace(True)
For i As Integer = 0 To st.FrameCount - 1
Dim sf As StackFrame = st.GetFrame(i)
Debug.WriteLine(vbCrLf & "Line: " & _
sf.GetFileLineNumber().ToString & _
" Method: " & sf.GetMethod().ToString)
Next
You will need to use the SelectionChangeCommitted event and not the SelectedIndexChanged event.
The SelectionChangeCommitted event works similar to SelectedIndexChanged event, the only difference is that the SelectedIndexChanged event gets fired when the ComboBox selection is changed from code i.e. during DataBinding or when the form is loaded.
So, if you populate your ComboBox in any place in your code, that should be the place where the event is triggered.

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

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.

How to detect what control triggers BeforeUpdate event in Access 2007

I have an audit trail that uses the BeforeUpdate event to track changes made on a subform using the following code:
`Dim USR As String
Dim TS As Date
Dim Connection As ADODB.Connection
Dim RecordSet As ADODB.RecordSet
Dim Ctl As Control
MsgBox "Here!"
Set Connection = CurrentProject.Connection
Set RecordSet = New ADODB.RecordSet
If Forms![PartsDatabaseX]![RepsSubformX].Visible = True Then
For Each Ctl In Screen.ActiveForm.RepsSubformX.Form.Controls
If Ctl.Tag = "Track" Then
If Nz(Ctl.Value) <> Nz(Ctl.OldValue) Then
SaveToken = True
With RecordSet
.AddNew
![Part Number] = Screen.ActiveForm.RepsSubformX.Form.Controls("[Part Nbr]").Value
![Record Identifier] = Screen.ActiveForm.RepsSubformX.Form.Controls("[Part Nbr]").Value & Screen.ActiveForm.RepsSubformX.Form.Controls("[Supplier Name]").Value
![Rep] = USR
![Time Stamp] = TS
![Change Point] = Ctl.ControlSource
![Change From] = Ctl.OldValue
![Change To] = Ctl.Value
.Update
End With
End If
End If
Next Ctl
End If`
The problem I am having is that is the user makes two changes there are three things recorded in my change history table - the first change to the record twice and the second change to the record once (this trend continues as long as the user never leaves the record). What I would like to do is be able to identify the control that triggered the BeforeUpdate event and pass it to the code above so it can check if only the control that triggered the BeforeUpdate event is different and skip the others that have already been logged. Alternatively, is there a way to prevent Access from seeing logged changes as new?
Forms and controls have Order of Events :
Similarly, when you close a form, the following sequence of events
occurs:
Exit (control) → LostFocus (control) → Unload (form) → Deactivate
(form) → Close (form)
If you've changed data in a control, the BeforeUpdate and AfterUpdate
events for both the control and the form occur before the Exit event
for the control.
You may wish to read http://support.microsoft.com/kb/197592
The answer has been staring me in the face the whole time... When I assign the BeforeUpdate event to each control, I can make it pass a variable to the function it calls to tell me the program what sent it:
Forms![PartsDatabaseX]![RepsSubformX].Form![Pack Rank].BeforeUpdate = "=ToTracking(""Pack Rank"")"
After that, it's a simple matter of adding an and statement when checking for changed values so it only captures the change that set off the BeforeUpdate event like so:
If Nz(Ctl.Value) <> Nz(Ctl.OldValue) And Ctl.ControlSource = NameOfTrigger Then
'Record Values
End if

Jump out of code if a button is pressed

Is there some way to have a 'listener' of sorts to listen for a button click in the middle of code? There are certain scenarios where I won't have to wait for the code to complete before I can exit the functions but I cannot seem to find a way to see if the button was clicked other than throwing a ton of if checks throughout the function calls which doesn't seem very efficient to me.
This code runs on the thread, different from your main application
private function LongRunningFunction()
Din canceled as boolean = false ' to make sure it is canceled while in the loop
' this is very long loop
For i as integer = 0 to 100000
If _cancelExecution Then
canceled = true
Exit For
End If
' your code runs here
.........
Next
If canceled Then
' Wrap up this thread, clean up stuff, etc
End If
.......................
End Function
On the main thread, when button is clicked _cancelExecution is set to true
The BackGroundWorker has this mechanism built-in already

How To activate Menu in OK and UPDATE mode

I enabled some menu in right click event. The first time it works well. For example 'Add Row' menu is pressed, it adds row. Again I right click button, and it's not showing the menus which I enabled in right click event. I need to add row again and again.
How can I achieve this?
Private Sub SBO_Application_RightClickEvent(ByRef eventInfo As SAPbouiCOM.ContextMenuInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.RightClickEvent
Try
oForm = SBO_Application.Forms.Item("TRADING")
If (eventInfo.FormUID = "TRADING") Then
oCombo = oForm.Items.Item("1000002").Specific
Dim oMenus As SAPbouiCOM.Menus
oMenus = SBO_Application.Menus
oForm.EnableMenu("1287", True)
oForm.EnableMenu("1292", True)
oForm.EnableMenu("1293", True)
If (oCombo.Selected.Value = "Open") Then
oMenus.Item("1283").Enabled = True
Else
oMenus.Item("1283").Enabled = False
End If
End If
Catch ex As Exception
End Try
End Sub
based on the input that u gave with your post, there may be two chance of getting error.
for the first time u are adding the row perfectly but in next time it was not working.. so i think code was not perfectly handled. try to place the same code in before action false. and also try to catch the action result that u get at item event so that we can debug the issue clearly.
to enable the right click event menu we need to handle the right click menu options based on oform.mode Separately.
for example in purchase order screen we will get different menu in add more and find mode.