Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21089

[RESOLVED] If no item in listview is selected and cancel button is selected, I receive an error.

$
0
0
Good morning,
I'm using the below to populate text boxes etc when clicking on a listview item.

Code:

Private Sub listview1_ItemClick(ByVal Item As MSComctlLib.ListItem)

Dim myLoan
strSQL = "SELECT Date_Entered, Loan_Number, Investor, State, Doc_type, Description, Number_Pages,Tracking_Number,Address, Processor, Reviewer1, executor1, Reviewer2, Executor2, Notes, Attorney, PLX, Clarifire_Completion, Attorney_Confirmation  FROM MailTeamTracker "


DTPicker1.Value = ListView1.SelectedItem.Text
txtLoanNumber.Text = ListView1.SelectedItem.SubItems(1)
cboInvestor.Text = ListView1.SelectedItem.SubItems(2)
cboState.Text = ListView1.SelectedItem.SubItems(3)
cboDocType.Text = ListView1.SelectedItem.SubItems(4)
txtDescription.Text = ListView1.SelectedItem.SubItems(5)
txtPages.Text = ListView1.SelectedItem.SubItems(6)
txtTracking.Text = ListView1.SelectedItem.SubItems(7)
txtAddress.Text = ListView1.SelectedItem.SubItems(8)
cboProcessor.Text = ListView1.SelectedItem.SubItems(9)
cboReviewer.Text = ListView1.SelectedItem.SubItems(10)
cboExecutors.Text = ListView1.SelectedItem.SubItems(11)
cboReviewer2.Text = ListView1.SelectedItem.SubItems(12)
cboExecutors2.Text = ListView1.SelectedItem.SubItems(13)
txtNotes.Text = ListView1.SelectedItem.SubItems(14)
cboLawFirm.Text = ListView1.SelectedItem.SubItems(15)
cboYesNo1.Text = ListView1.SelectedItem.SubItems(16)
cboClarifireTask.Text = ListView1.SelectedItem.SubItems(17)
cboYesNo2.Text = ListView1.SelectedItem.SubItems(18)

End Sub

the reason behind this is, they can click an edit button and change then update the values in the texboxes etc.

They can also choose to cancel the edit, and everything reverts to normal and does not update the record.
Now if I click the cancel command button and no listeview item was previously selected, i receive the error "object variable or with variable not set".

How can i change the below to do: If item selected then show selected item values in textboxes, if no item was selected, leave textboxes blank.
Code:

Private Sub cmdCancel_Click()

DTPicker1.Value = ListView1.SelectedItem.Text
txtLoanNumber.Text = ListView1.SelectedItem.SubItems(1)
cboInvestor.Text = ListView1.SelectedItem.SubItems(2)
cboState.Text = ListView1.SelectedItem.SubItems(3)
cboDocType.Text = ListView1.SelectedItem.SubItems(4)
txtDescription.Text = ListView1.SelectedItem.SubItems(5)
txtPages.Text = ListView1.SelectedItem.SubItems(6)
txtTracking.Text = ListView1.SelectedItem.SubItems(7)
txtAddress.Text = ListView1.SelectedItem.SubItems(8)
cboProcessor.Text = ListView1.SelectedItem.SubItems(9)
cboReviewer.Text = ListView1.SelectedItem.SubItems(10)
cboExecutors.Text = ListView1.SelectedItem.SubItems(11)
cboReviewer2.Text = ListView1.SelectedItem.SubItems(12)
cboExecutors2.Text = ListView1.SelectedItem.SubItems(13)
txtNotes.Text = ListView1.SelectedItem.SubItems(14)
cboLawFirm.Text = ListView1.SelectedItem.SubItems(15)
cboYesNo1.Text = ListView1.SelectedItem.SubItems(16)
cboClarifireTask.Text = ListView1.SelectedItem.SubItems(17)
cboYesNo2.Text = ListView1.SelectedItem.SubItems(18)


End Sub

Thanks in advanced!

Viewing all articles
Browse latest Browse all 21089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>