When i load a form a want to ask my users if they want to make a new record otherwise i would like to load the last record, this because the form will fill in some data by default.
Private Sub Form_Load()
Dim Nieuw
Nieuw = MsgBox("New Record?", vbYesNo, "New Record?")
If Nieuw = 6 Then
DoCmd.GoToRecord acDataForm, "Main", acNewRec
Else
DoCmd.GoToRecord acDataForm, "Main", acLast
End If
End Sub
When I use this script I got the following error
I couldn't find how to solve this issue
Just use the defaults:
Private Sub Form_Load()
Dim Nieuw As VbMsgBoxResult
Nieuw = MsgBox("New Record?", vbYesNo, "New Record?")
If Nieuw = vbYes Then
DoCmd.GoToRecord , , acNewRec
Else
DoCmd.GoToRecord , , acLast
End If
End Sub
Related
i have a textbox & and a button to filter data in my datagridview box, But i have also given a condition that if the form is under editing mode it should not allow filter.
Now the problem is once i click add new record button & even if i save the record, it always shows exception as the form is is editing mode can't filter.
Private Sub AddnewButton_Click(sender As Object, e As EventArgs) Handles AddnewButton.Click
'MsgBox("you preseed add new button")
Try
With AddnewButton
If .Text = "Add New Record" Then
MSdiesBindingSource.AddNew()
.Text = "Cancel"
Else
RefreshData()
MSdiesDataGridView.ClearSelection()
.Text = "Add New Record"
End If
End With
With Size_in_mgTextBox
If (.CanSelect) Then
.Text = String.Empty
.Select()
End If
End With
IsAddNewRecordInProgress = Convert.ToBoolean(AddnewButton.Text = "Cancel")
Catch ex As Exception
MsgBox("An error occured: " & ex.Message.ToString().ToString(),
MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Add new Record Failed")
End Try
End Sub
Private Sub RefreshData()
Try
'Me.MSdiesBindingSource.Filter = Nothing
MSdiesTableAdapter.Fill(Me.TrialdatabaseDataSet.MSdies)
MSdiesBindingSource.RemoveFilter()
Catch ex As Exception
MsgBox("Refresh Data Error!")
End Try
End Sub
Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
'MsgBox("you preseed add new button")
Try
Dim result As DialogResult
result = MessageBox.Show("Confirm Save?", "Save Data", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If (result = DialogResult.Yes) Then
Validate()
MSdiesBindingSource.EndEdit()
TableAdapterManager.UpdateAll(Me.TrialdatabaseDataSet)
MessageBox.Show("The record Has been saved",
"Save Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
RefreshData()
AddnewButton.Text = "Add New Record"
Else
' Exit Sub
Return
End If
Catch ex As Exception
MessageBox.Show("Save Data Failed: " & ex.Message.ToString(),
"Save Data", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub AlertWarningMessage()
'Do not allow search while addign record
MsgBox("The Search Function Is Disabled While Adding New Record",
MsgBoxStyle.OkOnly Or MsgBoxStyle.Exclamation, "Find Record")
End Sub
Private Sub SearchButton_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
ToolStripStatusLabel1.Text = "Status"
If IsAddNewRecordInProgress = True Then
AlertWarningMessage()
Exit Sub
End If
If Not String.IsNullOrEmpty(KeywordTextBox.Text) Then
SearchInAccessDatabase(KeywordTextBox.Text.Replace("'", "''"))
Else
RefreshData()
Return
End If
End Sub
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
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
'Exit from the main form & Display Message about the number of times Users rated.
Private Sub ExitApp()
Dim ans As DialogResult
Dim cns As DialogResult
ans = MessageBox.Show("Do you want to exit?", "Exit App", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If ans = DialogResult.Yes Then
cns = MessageBox.Show("Thanks for rating." & " " & "You have been rated" & " " & iOne1 & " " & "Times",
"Total Rating", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf cns = DialogResult.OK Then
me.close()
End If
End Sub
Use Nested if because you click on OK in next messagebox not the first one...
Dim ans As DialogResult
Dim cns As DialogResult
ans = MessageBox.Show("Do you want to exit?", "Exit App", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If ans = DialogResult.Yes Then
cns = MessageBox.Show("Thanks for rating." & " " & "You have been rated" & " " & iOne1 & " " & "Times",
"Total Rating", MessageBoxButtons.OK, MessageBoxIcon.Information)
If cns = DialogResult.OK Then
Me.Close()
End If
End If
Environment.Exit() should do what you need.
You have wrong if .. else. Checking for second dialog result need to be nested inside first if else. where in your case ElseIf cns = DialogResult.OK Then will never be reached.
Private Sub ExitApp()
Dim ans As DialogResult = MessageBox.Show("Do you want to exit?",
"Exit App",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
If ans = DialogResult.Yes Then
Dim message As String = $"Thanks for rating. You have been rated {iOne1} times"
Dim cns As DialogResult = MessageBox.Show(message,
"Total Rating",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
If cns = DialogResult.OK Then
Me.Close()
End If
End If
End Sub
Do not declare all variables in the beginning of function. Declare them only when you need, if you declared cns only when you created it, then your ElseIf will not even compiles, so you will be noticed about your "bug" during compile time.
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