Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / July 2006

Tip: Looking for answers? Try searching our database.

Excel Form and message box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pam Field - 22 Jul 2006 03:08 GMT
Hi there,

I'm running Excel 2000.  I am just learning so please excuse my questions if
they sound simple.

To put this as simply as possible I have a spreadsheet of children's names.
I've created a form that is activated by a control button.  What I want to
do is choose a child's name from the combo box and eventually delete that
child from the spreadsheet.  I have an "are you sure" type msgbox but cannot
get the yes/no side of it functioning correctly.  I've worked on this for
hours and have just given up.

This is my code so far:

Private Sub cboRemChild_Click()
   Dim myCell As Range
   Dim ChosenName As String
   Dim NameFound As Boolean
   Dim Ans 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

   MsgBox "Are you sure you want to remove this child?", vbYesNo

   If Ans = vbYes Then
    Selection.Delete Shift:=xlUp
    Range("A6").Select
   Else
       frmRemChild.Show
   End If
End Sub
-------------------
If either yes or no are chosen it performs the Else command.  What have I
done wrong?  It would also be great to have the Exclamation Mark icon appear
in this msgbox.  Oh yes, if you've got this far thank you very much for
taking the time to read my ramblings :-)

Thanks for any assistance in advance and I'm really sorry if my code looks
extremely amateur but that's me :-)

Regards
Pam
Maistrye - 22 Jul 2006 05:02 GMT
Pam Field Wrote:
> Hi there,
>
[quoted text clipped - 45 lines]
> Regards
> Pam

Hi Pam,

Try changing the following line:
MsgBox "Are you sure you want to remove this child?", vbYesNo

to this:
ans = MsgBox "Are you sure you want to remove this child?", vbYesNo

I think that should fix your problems.  (You just need to assign th
return value to your variable in order to be able to use it)

Scot
Pam Field - 22 Jul 2006 05:26 GMT
Thanks Scott,

Unfortunately that give me a 'syntax error' but your response has reminded
me that I don't have an actual ans= statement and I know I must have but
what and where?  I'm getting way to old to learn this stuff!

Any other assistance would be greatly appreciated.

cheers
Pam

> Hi Pam,
>
[quoted text clipped - 8 lines]
>
> Scott
JON JON - 22 Jul 2006 06:03 GMT
Hello,

Try this code

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

> Thanks Scott,
>
[quoted text clipped - 19 lines]
>>
>> Scott
Pam Field - 22 Jul 2006 06:02 GMT
Ok I've changed the variable to YesNo (found it on some website) and that
works now I just have some tidying up to do.  Hope nobody minds if I come
back with more questions on this one :-)

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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.