More help needed re form & msgbox

P

Pam Field

Thanks to those who helped earlier. I have two more questions (I hope
that's all). Once again my code so far is:

Private Sub cmdRemChild_Click()
Dim myCell As Range
Dim ChosenName As String
Dim NameFound As Boolean
Dim YesNo As Integer

ChosenName = cboChildName.Text
Sheets("Child Records").Select

NameFound = False
For Each myCell In Range("Name_of_Child")
If myCell.Value = ChosenName Then
myCell.Select
NameFound = True
Unload Me
Exit For
End If
Next myCell

If NameFound = False Then
MsgBox "Name not entered or not Found!"
cboChildName.SetFocus
End If

YesNo = MsgBox("Are you sure you want to remove this child?", vbYesNo +
vbExclamation, "Caution")

Select Case YesNo
Case vbYes
Selection.Delete Shift:=xlUp
Range("A6").Select
Case vbNo
frmRemChild.Show
End Select

End Sub
________________________

If I click on the cmdRemChild button without choosing a name I get msgBox
"Name not entered ......." - I click on no for this and it goes straight to
msgBox "Are you sure .........". What I want to happen if I don't choose a
name is for it to SetFocus on cboChildName. (It does this if I click on the
no from the msgBox "Are you sure .... etc".

Last problem (I hope) is that I want it to delete the entire row not just
the cell the name is in. Can someone please explain how I do this?

Thanks again so much for your help so far.

Regards
Pam
 
J

JON JON

Pam Field said:
Thanks to those who helped earlier. I have two more questions (I hope
that's all). Once again my code so far is:

Private Sub cmdRemChild_Click()
Dim myCell As Range
Dim ChosenName As String
Dim NameFound As Boolean
Dim YesNo As Integer

ChosenName = cboChildName.Text
Sheets("Child Records").Select

NameFound = False
For Each myCell In Range("Name_of_Child")
If myCell.Value = ChosenName Then
myCell.Select
NameFound = True
Unload Me
Exit For
End If
Next myCell

If NameFound = False Then
MsgBox "Name not entered or not Found!"
cboChildName.SetFocus
End If

YesNo = MsgBox("Are you sure you want to remove this child?", vbYesNo +
vbExclamation, "Caution")

Select Case YesNo
Case vbYes
Selection.Delete Shift:=xlUp
Range("A6").Select
Case vbNo
frmRemChild.Show
End Select

End Sub
________________________

If I click on the cmdRemChild button without choosing a name I get msgBox
"Name not entered ......." - I click on no for this and it goes straight
to msgBox "Are you sure .........". What I want to happen if I don't
choose a name is for it to SetFocus on cboChildName. (It does this if I
click on the no from the msgBox "Are you sure .... etc".

Last problem (I hope) is that I want it to delete the entire row not just
the cell the name is in. Can someone please explain how I do this?

Thanks again so much for your help so far.

Regards
Pam

Try this:



Private Sub cmdRemChild_Click()
Dim myCell As Range
Dim ChosenName As String
Dim NameFound As Boolean
Dim YesNo As Integer

ChosenName = cboChildName.Text

If Len(ChosenName) = 0 then
cboChildName.SetFocus
Exit Sub
End if
 
P

Pam Field

If Len(ChosenName) = 0 then
cboChildName.SetFocus
Exit Sub
End if


Thanks so much. This worked even though I will never know why :)

Now to beg for help with the absolute last question. How do I delete the
whole row instead of just the cell the name is in?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top