first record is selected automatically to delete

aru

Member
Hi I need a help,

I created a program for search result,
Here I have two button. 1) SEARCH 2 ) DELETE

When I click on search, all record will be displayed in the table.

And I can select a record to delete.
But If I am not select a record, and when I click on delete button, First record is deleted automatically or
first record is selected automatically to delete.

I don't want that type of deletion, deletion only after select a record.



My code is give below.
I want this program as when I press delete button, with out selection any record, any record won't be deleted.

Sub deleteStudent_Click
If SearchingStudent.RowCount <= SearchingStudent.SelectedRow Then Return
name = SearchingStudent.Cell (SearchingStudent.ColName(1),SearchingStudent.Sele ctedRow)
address = SearchingStudent.Cell (SearchingStudent.ColName(2),SearchingStudent.Sele ctedRow)
Msgbox(name)
Msgbox(address)
End Sub


Thanks and regards
Aru
 

mjcoon

Well-Known Member
Licensed User
It is probably easiest to have a global variable used as a boolean with meaning "record selected". You set it to false at program start and to true only when you have decided that a record has been selected.

Then test this variable before performing the deletion. Maybe if variable is false, show a message box saying "No explicit selection", or similar. Of course if the record is deleted then the variable must be set to false again!

HTH, Mike.
 

specci48

Well-Known Member
Licensed User
Longtime User
Have a look at my sample in the following post.

Of course it was a slightly different question, but if you take away one table you'll get a solution for you problem, too.


specci48
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…