Adding msgbox to code

sukyb1

Board Regular
Joined
Mar 27, 2009
Messages
153
I have the following code.
What this code does is take value from a combo box and fill out a text box. I need to change it so that if any of the combo boxes havent got a selected value then a message box appears saying "please fill out the whole form" at the moment i get a debug error because the value is null.

Private Sub cmdGenerate_Click()
Dim tmpStr As String
tmpStr = Left$(cboPWP.BoundValue, 7) & "-"
tmpStr = tmpStr & Left$(cboFunction.BoundValue, 3) & "-"
tmpStr = tmpStr & Left$(cboDT.BoundValue, 3) & "-"
tmpStr = tmpStr & Left$(cboOriginator.BoundValue, 50)
strCode = tmpStr
txtCode.Value = tmpStr
tmpStr = vbNullString
End If

Thanks in advance.
<!-- / message -->
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Code:
Private Sub cmdGenerate_Click()
Dim tmpStr As String
dim AllOK as Boolean

	Do Until AllOK

		If cboPWP.Value = "" Or _
			cboFunction.Value = "" Or _
			cboDT.Value = "" Or _
			cboOriginator.Value = "" Then
			
			MsgBox "Complete all details
		Else
		
			tmpStr = Left$(cboPWP.BoundValue, 7) & "-"
			tmpStr = tmpStr & Left$(cboFunction.BoundValue, 3) & "-"
			tmpStr = tmpStr & Left$(cboDT.BoundValue, 3) & "-"
			tmpStr = tmpStr & Left$(cboOriginator.BoundValue, 50)
			strCode = tmpStr
			txtCode.Value = tmpStr
			tmpStr = vbNullString
			
			AllOK = True
		End If
	Loop
End If
 
Upvote 0

Forum statistics

Threads
1,215,754
Messages
6,126,681
Members
449,328
Latest member
easperhe29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top