The following Outlook macro works perfectly, However, I would like this MsgBox to only appear if the Subject is LIKE 'Fees Due%' OR Subject is LIKE' Status Change%'. Is this possible?
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If MsgBox("Do you want to continue sending the mail?", vbOKCancel) <> vbOK Then
Cancel = True
End If
End Sub
Yes. Use Like operator:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.Subject Like "Fees Due*" Or Item.Subject Like "Status Change*" Then
If MsgBox("Do you want to continue sending the mail?", vbOKCancel) <> vbOK Then
Cancel = True
End If
End If
End Sub
I added outer If ... End If, nothing else was changed.
Should be
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim Subject As String
Subject = Item.Subject
If Subject Like "*Fees Due*" Or Subject Like "*Status Change*" Then
If MsgBox("Do you want to continue sending the mail?", _
vbYesNo + vbQuestion + vbMsgBoxSetForeground, _
"Check Subject") = vbNo Then
Cancel = True
End If
End If
End Sub
Related
This code is deleting the selected item in listview except for some reason it's showing the response 2 times and deleting the data twice. It should only appear once to confirm if i want to delete the item that i selected.
Dim response As Integer
For Each i As ListViewItem In ListView.SelectedItems
response = MsgBox("Are you sure you want to delete " + TextBox.Text, vbYesNo, "Confirm Delete")
If response = vbYes Then
ListView.Items.Remove(i)
End If
Next
You need to exit the for loop
Dim response As Integer
For Each i As ListViewItem In ListView.SelectedItems
response = MsgBox("Are you sure you want to delete " + TextBox.Text, vbYesNo, "Confirm Delete")
If response = vbYes Then
ListView.Items.Remove(i)
goto Here
End If
Next
Here:
by the way, this is vb.net, edit your post with vb.net tag please.
Step1 Changing ListView1 properties following below picture
enter image description here
Step2 Using this code:
Private Sub ListView1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles ListView1.ItemChecked
Dim i As ListViewItem
For Each i In ListView1.SelectedItems
Select Case MsgBox("Are you sure you want to delete selected record?", MsgBoxStyle.YesNo, "Confirm Delete")
Case MsgBoxResult.Yes
ListView1.Items.Remove(i)
Case MsgBoxResult.No
End Select
Next
End Sub
In my project, I use the code below (It is working):
Private Sub ListView1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles ListView1.ItemChecked
Dim i As ListViewItem
For Each i In ListView1.SelectedItems
Select Case MsgBox("คุณต้องการลบรายการขายสินค้าที่ถูกเลือกใช่ไหม", MsgBoxStyle.YesNo, "ยืนยันการลบรายการขายสินค้า")
Case MsgBoxResult.Yes
ListView1.Items.Remove(i)
txt_barcode.Text = ""
txt_barcode.Select()
txt_total.Text = FormatNumber(total_price)
txt_cost.Text = FormatNumber(total_buy)
txt_profit.Text = FormatNumber(total_price) - FormatNumber(total_buy)
txt_Quantity.Text = "1"
lbl_BarcodeID.Text = ""
lbl_Description.Text = ""
lbl_Price.Text = ""
Case MsgBoxResult.No
End Select
Next
End Sub
I made a program Reminder System that Auto send email when the date i set in my apps much the date in my computer. the problem is i need to restart my apps so that the reminder will show or the form will be loaded. if not it will not alert. so i need your help guys if the date change in my computer my apps will auto reload or refresh so that if have reminders it will be send to email. btw my program will be installed in a server that will always be open so i just need to auto reload my form every time the date change. below is my code in setting the reminders.
Imports System.IO
Public Class Reminder
Dim m As MsgBoxResult
Dim t As String
Private Sub Reminder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = TimeOfDay.ToString("h:mm:ss tt")
Dim m1 As MsgBoxResult
t = MonthCalendar1.SelectionRange.Start.Month.ToString & MonthCalendar1.SelectionRange.Start.Day.ToString
If Date.Today = MonthCalendar1.TodayDate And File.Exists(t & ".txt") = True Then
m1 = MsgBox("You set a reminders for today. Would you like to send to EMAIL ?", MsgBoxStyle.YesNo)
If m1 = MsgBoxResult.Yes Then
MonthCalendar1.Enabled = False
MonthCalendar1.Hide()
Notetxt.Enabled = True
Notetxt.Show()
SaveBtn.Enabled = True
SaveBtn.Show()
Backbtn.Enabled = True
Backbtn.Show()
Addbtn.Enabled = True
Addbtn.Show()
delbtn.Enabled = True
delbtn.Show()
Notetxt.Text = File.ReadAllText(t & ".txt")
sendEmail.Show()
sendEmail.emailtxt.Text = Notetxt.Text
sendEmail.Hide()
MsgBox("SEND EMAIL SUCCESSFUL", vbOKOnly)
lblMessage.Hide()
End If
End If
End Sub
Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
t = MonthCalendar1.SelectionRange.Start.Month.ToString & MonthCalendar1.SelectionRange.Start.Day.ToString
Try
If File.Exists(t & ".txt") = True Then
MonthCalendar1.Enabled = False
MonthCalendar1.Hide()
Notetxt.Enabled = True
Notetxt.Show()
SaveBtn.Enabled = True
SaveBtn.Show()
Backbtn.Enabled = True
Backbtn.Show()
Notetxt.Text = File.ReadAllText(t & ".txt")
Addbtn.Enabled = True
Addbtn.Show()
delbtn.Enabled = True
delbtn.Show()
lblMessage.Hide()
Else
m = MsgBox("Would you like to enter a reminders for this date?", MsgBoxStyle.YesNo)
If m = MsgBoxResult.Yes Then
MonthCalendar1.Enabled = False
MonthCalendar1.Hide()
Notetxt.Enabled = True
Notetxt.Show()
Notetxt.Text = ""
SaveBtn.Enabled = True
SaveBtn.Show()
Backbtn.Enabled = True
Backbtn.Show()
Addbtn.Enabled = True
Addbtn.Show()
delbtn.Enabled = True
delbtn.Show()
lblMessage.Hide()
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Backbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Backbtn.Click
Notetxt.Enabled = False
Notetxt.Hide()
MonthCalendar1.Enabled = True
MonthCalendar1.Show()
SaveBtn.Hide()
Addbtn.Hide()
delbtn.Hide()
Backbtn.Hide()
lblMessage.Show()
End Sub
Private Sub SaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveBtn.Click
t = MonthCalendar1.SelectionRange.Start.Month.ToString & MonthCalendar1.SelectionRange.Start.Day.ToString
Try
If Notetxt.Text = "" Then
If File.Exists(t & ".txt") = True Then
File.Delete(t & ".txt")
End If
End If
If Notetxt.Text.Length > 0 Then
File.WriteAllText(t & ".txt", Notetxt.Text)
MsgBox("SAVE SUCCESS", vbOKOnly)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Addbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addbtn.Click
Notetxt.Text = "Hi QC Engineer, Golden Sample meet Due date already please change." & Environment.NewLine & "MODEL: " & Environment.NewLine & "START DATE: " & Environment.NewLine & "DUE DATE: " & Environment.NewLine & "APPROVED BY: EAKKACHAI"
End Sub
Private Sub delbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delbtn.Click
Notetxt.Clear()
File.Delete(t & ".txt")
End Sub
End Class
and below is my code for sending email.
Public Class sendEmail
Private Sub sendEmail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Content As String
Content = emailtxt.Text
emailtxt.Text = Reminder.Notetxt.Text
Dim Outlook As New Microsoft.Office.Interop.Outlook.Application
Dim MailItem As Microsoft.Office.Interop.Outlook.MailItem
MailItem = Outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
With MailItem
.HTMLBody = emailtxt.Text
.Subject = "GOLDEN SAMPLE DUE DATE EXPIRED"
'use the below to change from the default email account
.SentOnBehalfOfName = "your#email.com"
'you can add multiple recipients using .Add()
.Recipients.Add("your#email.com")
'examples of other optional arguments that can be included
' .Attachments.Add([file])
.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh
.Send() 'opens the email for checking prior to sending or use .Send()
End With
End Sub
End Class
I have about 5 hidden textbox, and 1 button that when I click It it shows the hiddentext 1 by 1, but what I want to do is when I click the button once only 1 textbox appears and then a message box will appear saying "Do you want to Continue" YES or NO? if I press Yes, then the 2nd textbox will appear, but when I press No the messagebox should be closed.
I have this Code on the Button:
Private Sub revealtxtbox_Click(ByVal senders As System.Object, ByVal e As System.EventArgs) Handles revealtxtbox.Click
txtbox1.visible = True
If MsgBox("Do you Want to Continue", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Sample System") = MsgBoxResult.Yes then
txtbox2.visible = true
Elseif MsgBoxResult.Yes then
txtbox3.visible = true
Elseif MsgBoxResult.Yes then
txtbox4.visible = true
Elseif MsgBoxResult.Yes then
txtbox5.visible = true
End if
the code above somewhat works but when I press NO, the txtbox3 shows and the msgbox closed, it should not show txtbox3, it should only close the msgbox.
Try something more like this instead:
Private Sub revealtxtbox_Click(ByVal senders As System.Object, ByVal e As System.EventArgs) Handles revealtxtbox.Click
txtbox1.visible = True
If MsgBox("Do you Want to Continue", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Sample System") <> MsgBoxResult.Yes then
Exit Sub
End If
txtbox2.visible = true
If MsgBox("Do you Want to Continue", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Sample System") <> MsgBoxResult.Yes then
Exit Sub
End If
txtbox3.visible = true
If MsgBox("Do you Want to Continue", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Sample System") <> MsgBoxResult.Yes then
Exit Sub
End If
txtbox4.visible = true
If MsgBox("Do you Want to Continue", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Sample System") <> MsgBoxResult.Yes then
Exit Sub
End If
txtbox5.visible = true
End if
I was wondering how can I display a pop up warning message every time the selected item in dropdown list has changed. I've managed to get it working , but the message will unfortunately also pop up when loading the form as in some cases the default value has already been set and is not empty. So far i have this:
Private Sub cboNew_DropDown(sender As Object, e As EventArgs) Handles cboNew.SelectedIndexChanged
If cboNew.SelectedItem = "%" Then
MessageBox.Show(String.Format(" You Selected = " & cboNew.SelectedItem, MessageBoxButtons.OK))
End If
If cboNew.SelectedItem = "Value" Then
MessageBox.Show(String.Format(" You Selected = " & cboNew.SelectedItem, MessageBoxButtons.OK))
End If
If cboNew.SelectedItem = "REVOKE" Then
MessageBox.Show(String.Format(" You Selected = " & cboNew.SelectedItem, MessageBoxButtons.OK))
End If
End Sub
Sometime it's hard to determine where the error came from. You could add a boolean flag to help you out.
Private _isLoading As Boolean = False
Private Sub YourLoadingSub
_isLoading = True
' Do your loading code
_isLoading = False
End Sub
Private Sub cboNew_DropDown(sender As Object, e As EventArgs) Handles cboNew.SelectedIndexChanged
If Not _isLoading Then
' Show message box
End If
End Sub
An other option is to remove the event and put it back when needed.
The mistake is in this statement MessageBox.Show( change this as msgbox() then your code will be like the following:
Private Sub cboNew_DropDown(ByVal sender As Object, ByVal e As EventArgs) Handles cboNew.SelectedIndexChanged
If cboNew.SelectedItem = "%" Then
MsgBox(String.Format(" You Selected = " & cboNew.SelectedItem, MessageBoxButtons.OK))
End If
If cboNew.SelectedItem = "Value" Then
MsgBox(String.Format(" You Selected = " & cboNew.SelectedItem, MessageBoxButtons.OK))
End If
If cboNew.SelectedItem = "REVOKE" Then
MsgBox(String.Format(" You Selected = " & cboNew.SelectedItem, MessageBoxButtons.OK))
End If
End Sub
How can i prevent that the ItemAdd Event firing again after item.save
At the moment i get an endless loop
Private Sub yFld_ItemAdd(ByVal item As Object)
If Left(item.Subject, 16) Like "Visit from Mail:" And IsNumeric(Mid(item.Subject, 17)) Then
x = newVisit(CLng(Mid(item.Subject, 17)))
item.Subject = "checked: " & item.Subject & " " & x
item.Save
End If
End Sub
Use flag to deside to save item or not:
Dim ItemChecked as Boolean
Private Sub ThisAddIn_Startup() Handles Me.Startup
...
ItemChecked = False
End Sub
Private Sub yFld_ItemAdd(ByVal item As Object)
If Not ItemChecked Then
...
mail.Save()
ItemChecked = True
Else
ItemChecked = False
End If
End Sub
It works in my case.
ItemAdd will not fire. ItemChange will.