Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help! MsgBox and Prevent Save

I have 3 textboxes lined up horizontally on a sheet... I have a cmd
button on the far right that loses the focus from the textboxes and
saves the workbook. See below....

'....loses focus of textboxes
Private Sub Commandbutton_Click()
Me.TxBName.Enabled = CBool(Me.TxBName.Value = "")
Me.TxBAddress.Enabled = CBool(Me.TxBAddress.Value = "")
Me.TxBCity.Enabled = CBool(Me.TxBCity.Value = "")
'....saves workbook
ActiveWorkbook.Save
End Sub

My question, how do I force the user to fill all textboxes. For example
an user completes the name and address textboxes but fails to complete
the city textbox... then he/she presses the cmd button... I want a
msgbox to pop up "complete all fields before booking" and would not let
him/her save the workbook. How do I accomplish this???


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help! MsgBox and Prevent Save

You are already checking if the textbox is empty. Use the same logic with
an IF statement to put up a msgbox, then exit the sub so the workbook is not
saved.

--
Regards,
Tom Ogilvy

"nrage21 " wrote in message
...
I have 3 textboxes lined up horizontally on a sheet... I have a cmd
button on the far right that loses the focus from the textboxes and
saves the workbook. See below....

'....loses focus of textboxes
Private Sub Commandbutton_Click()
Me.TxBName.Enabled = CBool(Me.TxBName.Value = "")
Me.TxBAddress.Enabled = CBool(Me.TxBAddress.Value = "")
Me.TxBCity.Enabled = CBool(Me.TxBCity.Value = "")
'....saves workbook
ActiveWorkbook.Save
End Sub

My question, how do I force the user to fill all textboxes. For example
an user completes the name and address textboxes but fails to complete
the city textbox... then he/she presses the cmd button... I want a
msgbox to pop up "complete all fields before booking" and would not let
him/her save the workbook. How do I accomplish this???


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help! MsgBox and Prevent Save

Hi,
Add following if statement :

if Me.TxBName.Enabled<"" And Me.TxBAddress.Enabled<"" And
Me.TxBCity.Enabled Then
Activeworkbook.Save
else
Msgbox "Please fill out all the fields"
end if


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help! MsgBox and Prevent Save

'....loses focus of textboxes
Private Sub Commandbutton_Click()
Me.TxBName.Enabled = CBool(Me.TxBName.Value = "")
Me.TxBAddress.Enabled = CBool(Me.TxBAddress.Value = "")
Me.TxBCity.Enabled = CBool(Me.TxBCity.Value = "")
if Me.TxBName.Enabled<"" And Me.TxBAddress.Enabled<"" And
Me.TxBCity.Enabled<"" Then Activeworkbook.Save
else
Msgbox "Please fill out all the fields"
end if
End Sub

:( It doesn't work... what am I doing wrong??


- Larry -
VBA Amateur


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help! MsgBox and Prevent Save

Sorry, is my fault,

I just copied the lines without reading. should be like this :

if Me.TxBName<"" And Me.TxBAddress<"" And Me.TxBCity<"" The
Activeworkbook.Sav

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help! MsgBox and Prevent Save

I made the change.... I get an error message..

End without If !!!!


:(
nrage2

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help! MsgBox and Prevent Save

Hi,

If you have a statement after "then" on the same line, you don't nee
an "end if"

The correct syntax is as follows :

if Me.TxBName<"" And Me.TxBAddress<"" And Me.TxBCity<"" Then
Activeworkbook.Save
else
msgbox
end i

--
Message posted from http://www.ExcelForum.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help! MsgBox and Prevent Save

Thanks Tolgag... you're the man... It's finally working

final code:

Private Sub CommandButton1_Click()
'....loses focus of textbox
Me.TextBox1.Enabled = CBool(Me.TextBox1.Value = "")
Me.TextBox2.Enabled = CBool(Me.TextBox2.Value = "")
Me.TextBox3.Enabled = CBool(Me.TextBox3.Value = "")
'....if user leaves a textbox blank triggers messagebox and sets focus
if user completes everything then locks textbox and saves. Nice Tolgag
If Me.TextBox1 < "" And Me.TextBox2 < "" And Me.TextBox3 < "" Then
ActiveWorkbook.Save
Else
MsgBox "Unable to book"
Me.TextBox1.Enabled = True
Me.TextBox2.Enabled = True
Me.TextBox3.Enabled = True
End If
End Sub


:) nrage21 <= happy camper!

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent dialogue: "save changes"? [email protected] New Users to Excel 4 May 16th 10 05:34 PM
Prevent color change open/save sheet? Julie Moorehouse Excel Discussion (Misc queries) 0 July 29th 09 03:35 PM
Prevent from save if... Pietro Excel Discussion (Misc queries) 4 July 26th 08 09:40 AM
HOW CAN I PREVENT EXCEL FILES FROM BEING DELETED OR PREVENT TRASH ROB Excel Discussion (Misc queries) 2 April 2nd 07 01:13 PM
prevent user from saving file to a folder but allow my code to save from behind. susie Excel Programming 3 July 25th 03 03:01 PM


All times are GMT +1. The time now is 03:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"