When using the Form.Delete event on a continuous form, the message is displaying twice.
My Access version is 2111 (Build 14701.20226)
Has anyone else run into this?
Private Sub Form_Delete(Cancel As Integer)
Cancel = True
MsgBox "This record can't be deleted."
End Sub
Related
I want to run a Macro in Outlook at a certain time and so I'm using the Outlook Reminders to do it. I have written the below code, which successfully runs the Macro but after it has finished the If statement, it then pops up the reminder which I don't need to see and so therefore need to close/dismiss it.
Public Sub Application_Reminder(ByVal Item As Object)
If Item.Subject = "Refresh Data Test" Then
Call RunExcelMacros.TestRun
End If
End Sub
Please can someone help suggest how I can dismiss the reminder?
Okay, I think I've got it - the below seems to work, all code is setup in the "ThisOutlookSession" Module:
Private WithEvents OutlookReminders As Outlook.Reminders
Public Sub Application_Reminder(ByVal Item As Object)
Set OutlookReminders = Outlook.Reminders
If Item.Subject = "Refresh Data Test" Then
Call RunExcelMacros.TestRun
End If
End Sub
Private Sub OutlookReminders_BeforeReminderShow(Cancel As Boolean)
Dim OutlookReminder As Reminder
'After the "Application_Reminder" has run it will then run this code straight after which stops the reminder from actually popping up
For Each OutlookReminder In OutlookReminders
If OutlookReminder.Caption = "Refresh Data Test" Then
If OutlookReminder.IsVisible Then
OutlookReminder.Dismiss
Cancel = True
End If
Exit For
End If
Next OutlookReminder
End Sub
I am sending mail using outlook, on send event I am trying to display message, but msgbox is not getting displayed till I clicked on screen( anywhere).
(Once user click on Send in Outlook, I am changing the Outlook windowState to minimize.)
Public Sub oApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
If(StrComp(clickedEvent, "ClickMe", vbTextCompare) = 0) Then
MsgBox "HI"
end if
End sub
Thanks
This is a known issue with several MS Office applications. Try adding this code and see if it helps:
AppActivate Application.Caption
or
AppActivate "Microsoft Excel" ' name of application that needs to be in focus
From the documentation:
The AppActivate statement changes the focus to the named
application or window but does not affect whether it is maximized or
minimized.
Sometimes trying to accomplish the most minor turns into a major headache... I somehow corrupted a database while experimenting to solve this issue. Now I'm really determined to figure this out. (I'll worry about the corrupt DB later!)
End Goal:
When opening .accdb file, automatically:
open form unbound)
run code to:
get Last Update Date from table
display Last Update Date in textbox on form (must be visible to user)
if table data is outdated, run code to:
update data in table
display Update Progress Message(s) in textbox on form (must be visible to user)
when finished:
display Last Update Date in textbox on form (must be visible to user)
The problem is the goal of (must be visible to user).
I can't get the form to display anything until all the code's finished running, regardless of how I run the code (including: set the form to auto-open with File → Options → Display Form; add an AutoExec macro to call code to open the form and run the update; or, run it manually.)
I've been experimenting with the form's opening events to see if I missed something.
According to the Order of Events documentation:
Working with data on a form
Form and control events occur as you move between records in the form and change data. For example, when you first open a form, the following sequence of events occurs:
Open (form) → Load (form) → Resize (form) → Activate (form) → Current (form) → Enter (control) → GotFocus (control)
At no point does the form visibly update. I've tried adding Me.Repaint and even tried Echo=True and DoEvents but obviously they didn't change anything.
My code for testing:
Private Sub Form_Open(Cancel As Integer)
txtTest = "Form_Open()": MsgBox "1. Form_Open"
End Sub
Private Sub Form_Load()
txtTest = "Form_Load()": MsgBox "2. Form_Load"
End Sub
Private Sub Form_Current()
txtTest = "Form_Current()": MsgBox "3. Form_Current"
End Sub
Private Sub txtTest_Enter()
txtTest = "txtTest_Enter()": MsgBox "4. txtTest_Enter"
End Sub
Private Sub txtTest_GotFocus()
Echo True : Repaint : DoEvents
txtTest = "txtTest_GotFocus()": MsgBox "5. txtTest_GotFocus"
End Sub
Private Sub txtTest_Change() : MsgBox "This Does't Run!" : End Sub
Private Sub Form_AfterUpdate() : MsgBox "This Does't Run!" : End Sub
Private Sub txtTest_Change() : MsgBox "This Does't Run!" : End Sub
Private Sub txtTest_BeforeUpdate(Cancel As Integer) : MsgBox "This Does't Run!" : End Sub
Private Sub txtTest_AfterUpdate() : MsgBox "This Does't Run!" : End Sub
The result of opening the form:
(Note that the form's Activate and AfterUpdate events and the control's Change, BeforeEvent and AfterEvent events do not fire at all.)
Theoretically, the form should be visible behind the MsgBox, but neither running the actual update code, nor running a "pause" (loop with DoEvents) doesn't display the form either.
I could swear I've done this in the past without issue but no matter what I do try, the form only displays once all code is finished running.
You can use the Form_Timer event to delay execution until the form fully finishes loading.
Private Sub Form_Load()
Me.TimerInterval = 1 'Trigger 1 millisecond, but asynchronously from other tasks
'Triggers after AutoExec macro has finished
End Sub
Private Sub Form_Timer()
Me.TimerInterval = 0 'Trigger only once
'Your other tasks here
End Sub
I see this code all over the internet and everyone says how wonderful it works but it doesn't for me, I'm clueless, any ideas why?
I have Windows 7 and Outlook 2010.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
strSubject = Item.Subject
If Len(Trim(strSubject)) = 0 Then
Prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
End Sub
Please ensure you have set the correct references in your project for Outlook 2010 Library. Also ensure that Outlook 2010 should already be in running state. Thanks
you posted a link to a screen capture on May 20 at 16:04
go to that same place in the code and delete all the code in the sub, including sub and endsub (the code that you posted)
now click on "application" dropdown at top-left
you should see the following fill in
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
End Sub
if something else pops up, then click on ItemSend in dropdown on top right
put in one command to get this very minimal sub (if it does not work, then nothing else will)
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
msgbox "this works"
End Sub
now send any email, if it works then you should see a dialog box pop up
note: i have found that "just pasting in code" does not always work and you have to click on the dropdown menus, after you paste in the code, to get the sub to be registered
I have been searching the internet for this all day. But no luck.
Can you setup events for when you enter/leave a tab.
I.E.
OnExit(Tab1)
Do something
Thanks
Depending on your program flow, you might try:
Private Sub Combo3_Exit(Cancel As Integer)
If IsNull(Me.Combo3) Then
MsgBox "No exit"
Cancel = True
End If
End Sub
Private Sub Form_Current()
Me.Combo3.SetFocus
''Or to refer to a subform from the main form
Me.subformcontrolname.Form.Combo3.SetFocus
End Sub
Does the tab contain a subform or only controls from the main form?
A subform has an Exit event, so if you are only concerned that once you have entered the subform you should not leave without completing data, you could:
Private Sub subformcontrolname_Exit(Cancel As Integer)
If IsNull(Me.subformcontrolname.Form.Combo3) Then
Me.subformcontrolname.Form.Combo3.SetFocus
MsgBox "No exit"
Cancel = True
End If
End Sub
While this is not exactly what you want, you could instead of handling the exit simply prevent the user from clicking somewhere else. To do this, attach some code to your combobox1 that bascially set .Enabled=Xfor all elements outside your tab view - where X is determined by the state of the combobox...