-
Aug 19th, 2022, 12:56 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Command line, Me.Close() skipped
I am having quite a time figuring out what is going on with the behavior of the form shown below.
The form, is broken down into several containers, Change Request, Change Content, and Change Status. The first two containers are for user inputs to the record.
The textboxes in the Change Status container are all formatted for short dates. The first is self-generated and never editable, while the rest of them have been set to auto-input the current date by just clicking in the textbox.
At this point the user might click the Save button. Note that all of the available inputs have not been entered. The code below, in the Case Else branch, defines the conditions that the record will not be saved. Under this condition, if the date submitted has been filled and any of the inputs remain blank, the method will clear the Date Submit and allow the user the chance to fill in the form, or abandon the effort by clicking the Cancel button.
What occurs is that none of the inputs are editable and if the user clicks the cancel button the form does execute Me.Close(). However, everything after the Me.Close() is executed. What one is left with is the form is still open, as is the form that the method called out.
Should the user choose to first click the Date Submitted textbox, the date fills in and the user is now allowed to edit the form inputs and clicking the Cancel button will now execute completely (the record is not updated). Or the user can click the Save button and update the record.
While I suspect that there is some relation between the validation method and the apparent skip of the Me.Close() command, I have no idea what that might be. Not only that, but my suspicions are usually far from what really occurs and I don't really have a grasp of what/how validation works.
What I want is two things. The first is the user to be able to complete the form correctly and then save their edits (assuming the edits meet the criteria). It does this. Or to be able to just click the Cancel Button and close the form without saving. It does not do this.
Code:
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Select Case MyState
#Region "Case Else"
Case Else
If Not String.IsNullOrWhiteSpace(txtSubmit.Text) And (String.IsNullOrWhiteSpace(txtName.Text) Or
Not String.IsNullOrWhiteSpace(cboManager.Text) Or Not String.IsNullOrWhiteSpace(cboOwner.Text) Or
Not String.IsNullOrWhiteSpace(txtMade.Text) Or Not String.IsNullOrWhiteSpace(txtResult.Text)) Then
MessageBox.Show("All information must be filled out in the form.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtSubmit.Text = ""
txtSubmit.ReadOnly = False
'txtApprove.ReadOnly = True
Else
If Not String.IsNullOrWhiteSpace(txtEffective.Text) And chkObsolete.Checked = False Then
RecEffective.MakeEffective(lblChangeType.Text, lblArticleID.Text)
chkActive.Checked = False
End If
UpdateRecord()
MessageBox.Show("Record saved.", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
chgList.Show()
End If
#End Region
End Select
End Sub
Code:
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click, btnCancel.Click
Me.Close()
Select Case MyUser
Case "DocMaster"
If MySystem = "Article" Then docList.Show() Else chgList.Show()
Case "PartMaster"
If MySystem = "Article" Then partList.Show() Else chgList.Show()
Case "AssyMaster"
If MySystem = "Article" Then fabList.Show() Else chgList.Show()
Case "ValMaster"
If MySystem = "Article" Then valList.Show() Else chgList.Show()
Case "DevMaster"
If MySystem = "Article" Then devList.Show() Else chgList.Show()
End Select
End Sub
Code:
Private Sub txtSubmit_Click(sender As Object, e As EventArgs) Handles txtSubmit.Click
If String.IsNullOrWhiteSpace(txtSubmit.Text) And txtSubmit.ReadOnly = False Then txtSubmit.Text = Today.ToShortDateString Else MsgBox("This input cannot be changed.")
End Sub
Code:
Private Sub txtSubmit_Validating(sender As Object, e As CancelEventArgs) Handles txtSubmit.Validating
If String.IsNullOrWhiteSpace(txtSubmit.Text) Then Exit Sub
If Not IsDate(txtSubmit.Text) Or CDate(txtSubmit.Text) <> Today Then
MsgBox("Please enter a valid current date.", vbCritical)
txtSubmit.SelectionStart = 0
txtSubmit.SelectionLength = Len(txtSubmit.Text)
txtSubmit.Focus()
End If
End Sub
-
Aug 19th, 2022, 01:42 PM
#2
Re: Command line, Me.Close() skipped
What I want is two things. The first is the user to be able to complete the form correctly and then save their edits (assuming the edits meet the criteria). It does this. Or to be able to just click the Cancel Button and close the form without saving. It does not do this.
If you want to do something when they select "Cancel" then you have to check for that.
Code:
If MessageBox.Show("Retry", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.Cancel Then
Me.Close()
End If
-
Aug 19th, 2022, 02:23 PM
#3
Re: Command line, Me.Close() skipped
I'm confused about what is actually happening. You said that Me.Close is executed on Cancel, but that everything after it is also executed. However, you showed the Save button, not the Cancel button. Is the Cancel button working correctly? Is this issue with the Save button?
Ah, I see that the close button is also the Cancel button. It seems to be doing what you told it to do. Me.Close is not the same as Return, nor do you appear to want it to be.
My usual boring signature: Nothing
-
Aug 19th, 2022, 03:23 PM
#4
Thread Starter
Fanatic Member
Re: Command line, Me.Close() skipped
I too am confused. And I am the one who put this together. I am beginning to see that my issue might well be with the txtSubmit_Click() event (see above). This issue only occurs if I skip filling in the txtSubmit textbox.
Let's just take a look at a rough depiction of the process
btnClose and btnCancel are currently both handled in the same event method BTW.
Actually, as I re-re-review the code and look at the process, it appears to me that I have set the process up such that there must be an input to the txtSubmit txtbox. This probably has something to do with the fact that I have the txtSubmit textbox set such that if one clicks the textbox, the Today short date is auto generated.
Having said all of that, where would the event method suggested by Wes go?
-
Aug 19th, 2022, 03:40 PM
#5
Thread Starter
Fanatic Member
Re: Command line, Me.Close() skipped
I just worked through it all again and it comes down to taking out the line of code, in the btnSave_Click() Event, txtSubmit = "". I had thought that the form would be better if I cleared that textbox when the input validation failed. Obviously, I was wrong.
Having said all of that, I still am not clear on why it all goes south if the txtSubmit textbox is cleared. I have noticed that none of the outputs are editable, and of course the cancel button does not execute the Me.Close() line of the btnClose/btnCancel event.
-
Aug 19th, 2022, 03:42 PM
#6
Re: Command line, Me.Close() skipped
Having said all of that, where would the event method suggested by Wes go?
That would be in the btnsave_click event. If they select Cancel then it would exit without updating anything.
I didn't notice that the Close and Cancel button use the same Click event. Not sure why you do that, a person might want to cancel the current changes but not close the form. But maybe that's not a possibility.
-
Aug 19th, 2022, 03:49 PM
#7
Thread Starter
Fanatic Member
Re: Command line, Me.Close() skipped
got it! So your code then sets up for if the cancel button is clicked, instead of making the edits and refilling txtSubmit?
Thanks. In retrospect, I really am not sure why I even thought it was a good idea to clear the txtSubmit textbox, since if one is going to cancel without saving, it doesn't matter if the txtSubmit textbox is clear or not.
-
Aug 19th, 2022, 04:02 PM
#8
Re: Command line, Me.Close() skipped
Originally Posted by gwboolean
got it! So your code then sets up for if the cancel button is clicked, instead of making the edits and refilling txtSubmit?
Thanks. In retrospect, I really am not sure why I even thought it was a good idea to clear the txtSubmit textbox, since if one is going to cancel without saving, it doesn't matter if the txtSubmit textbox is clear or not.
Really, it was just an example of how to use the MessageBox Cancel button to close the form. Your giving me to much credit. lol
-
Aug 19th, 2022, 04:24 PM
#9
Thread Starter
Fanatic Member
Re: Command line, Me.Close() skipped
To be honest, I don't believe your change will work either. I believe the problem lies in the validation method for the textbox (see above). I haven't figured it out yet, but I think that the criteria/parameters for that method are not correct to cover the cleared textbox.
-
Aug 19th, 2022, 04:41 PM
#10
Re: [RESOLVED] Command line, Me.Close() skipped
Code:
If Not IsDate(txtSubmit.Text) Or CDate(txtSubmit.Text) <> Today
Do you realize that "Today" returns a date and time?
-
Aug 19th, 2022, 05:06 PM
#11
Thread Starter
Fanatic Member
Re: [RESOLVED] Command line, Me.Close() skipped
Originally Posted by wes4dbt
Code:
If Not IsDate(txtSubmit.Text) Or CDate(txtSubmit.Text) <> Today
Do you realize that "Today" returns a date and time?
I do. Is that causing me a problem? Personally, I would prefer to have just the date, since I remember the time element has caused me problems in the past. Is it easy for me to eliminate the time element?
-
Aug 19th, 2022, 08:42 PM
#12
Re: [RESOLVED] Command line, Me.Close() skipped
Originally Posted by wes4dbt
Code:
If Not IsDate(txtSubmit.Text) Or CDate(txtSubmit.Text) <> Today
Do you realize that "Today" returns a date and time?
It does, but the time part is zero. Today is equivalent to Now.Date. In fact, it's probably implemented that way because DateTime.Today is implemented as DateTime.Now.Date.
-
Aug 20th, 2022, 02:37 AM
#13
Re: [RESOLVED] Command line, Me.Close() skipped
Originally Posted by jmcilhinney
It does, but the time part is zero. Today is equivalent to Now.Date. In fact, it's probably implemented that way because DateTime.Today is implemented as DateTime.Now.Date.
Thanks, I didn't know "CDate("8/20/2022")=Today" would evaluate to True. To be honest I haven't used Cdate in years. forgot it also has a time of 12:00:00 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|