PDA

View Full Version : Reminder to input Data on User form



maninjapan
09-10-2008, 11:14 PM
I am trying to make a userform that requires multiple data entries.
Clicking the Ok button enters all the data into spreadsheet.
However if even one piece of Data is missing I want it to bring up a warning stating what needs to be entered. I have tried this for one piece of data and the MsgBox works fine, however it still enters the rest of the data. Im trying to get it to only transfer the data to the spreadsheet once all the data is entered correctly.
So far this is what I have......

Private Sub CommandNextContract_Click()
' Make sure Sheet1 is active
Sheets("Sheet1").Activate

' Determine the next empty row
NextRow = _
Application.WorksheetFunction.CountA(Range("A:A")) + 1
' Transfer the Date,Trader,Contract,Month,Lots,P&L,Currency
Cells(NextRow, 1) = TextBoxDate.Text
Cells(NextRow, 2) = ComboBoxTrader.Text
Cells(NextRow, 3) = ComboBoxContract.Text
Cells(NextRow, 4) = ComboBoxmonth.Text
Cells(NextRow, 5) = TextBoxLots.Text
Cells(NextRow, 6) = TextBoxPL.Text
Cells(NextRow, 7) = ComboBoxCurrency.Text

' Clear Trade Info for next entry
ComboBoxContract.Text = ""
ComboBoxmonth.Text = ""
TextBoxLots.Text = ""
TextBoxPL.Text = ""
ComboBoxCurrency.Text = "USD"
ComboBoxContract.SetFocus

' Ensures Trader is selected
If ComboBoxTrader.Text = "" Then
MsgBox "Please select Trader"
ComboBoxTrader.SetFocus
Exit Sub
End If
End Sub

slamet Harto
09-10-2008, 11:24 PM
hoping this help

Private Sub CommandNextContract_Click()
' Make sure Sheet1 is active
Sheets("Sheet1").Activate

'You need to add this line
if TextBoxDate.Text= "" Then
MsgBox "Enter Date! ", vbInformation, "Error message"
TextBoxDate.Text.SetFocus
Exit Sub
End If

if ComboBoxTrader.Text= "" Then
MsgBox "Enter Date! ", vbInformation, "Error message"
ComboBoxTrader.Text.SetFocus
Exit Sub
End If

' and so on


' Determine the next empty row
NextRow = _
Application.WorksheetFunction.CountA(Range("A:A")) + 1
' Transfer the Date,Trader,Contract,Month,Lots,P&L,Currency
Cells(NextRow, 1) = TextBoxDate.Text
Cells(NextRow, 2) = ComboBoxTrader.Text
Cells(NextRow, 3) = ComboBoxContract.Text
Cells(NextRow, 4) = ComboBoxmonth.Text
Cells(NextRow, 5) = TextBoxLots.Text
Cells(NextRow, 6) = TextBoxPL.Text
Cells(NextRow, 7) = ComboBoxCurrency.Text

' Clear Trade Info for next entry
ComboBoxContract.Text = ""
ComboBoxmonth.Text = ""
TextBoxLots.Text = ""
TextBoxPL.Text = ""
ComboBoxCurrency.Text = "USD"
ComboBoxContract.SetFocus

' Ensures Trader is selected
If ComboBoxTrader.Text = "" Then
MsgBox "Please select Trader"
ComboBoxTrader.SetFocus
Exit Sub
End If
End Sub

maninjapan
09-10-2008, 11:36 PM
Thanks for that. all the messages are good now. But it still enters the data even if one piece is missing. I want it to only enter data to the worksheet if all the data is entered correctly....

Bob Phillips
09-11-2008, 01:07 AM
Private Sub CommandNextContract_Click()
If TextBoxDate.Text = "" Or _
ComboBoxTrader.Text = "" Or _
ComboBoxContract.Text = "" Or _
ComboBoxmonth.Text = "" Or _
TextBoxLots.Text = "" Or _
TextBoxPL.Text = "" Or _
ComboBoxCurrency.Text = "" Then

MsgBox "Incomplete Data!", vbInformation, "Error message"
TextBoxDate.Text.SetFocus
Exit Sub
Else

' Make sure Sheet1 is active
Sheets("Sheet1").Activate

' Determine the next empty row
NextRow = _
Application.WorksheetFunction.CountA(Range("A:A")) + 1
' Transfer the Date,Trader,Contract,Month,Lots,P&L,Currency
Cells(NextRow, 1) = TextBoxDate.Text
Cells(NextRow, 2) = ComboBoxTrader.Text
Cells(NextRow, 3) = ComboBoxContract.Text
Cells(NextRow, 4) = ComboBoxmonth.Text
Cells(NextRow, 5) = TextBoxLots.Text
Cells(NextRow, 6) = TextBoxPL.Text
Cells(NextRow, 7) = ComboBoxCurrency.Text

' Clear Trade Info for next entry
ComboBoxContract.Text = ""
ComboBoxmonth.Text = ""
TextBoxLots.Text = ""
TextBoxPL.Text = ""
ComboBoxCurrency.Text = "USD"
ComboBoxContract.SetFocus
End If
End Sub