View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default user input recorded twice on excel sheet


Hi Bob, Thanks for the reply. I am still having an issue with this.

here is a part of my code.

Pivate Sub Submit_Click()

Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

'check for Officer Name
If Trim(Me.OfficerNm.Value) = "" Then
Me.OfficerNm.SetFocus
MsgBox "Please enter your Name"
Exit Sub
End If

'check for Amount Name
If Trim(Me.Amt.Value) = "" Then
Me.Amt.SetFocus
MsgBox "Please enter a Amount"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.OfficerNm.Value
ws.Cells(iRow, 2).Value = Me.CostCntr.Value
ws.Cells(iRow, 3).Value = Me.AcctNo.Value
ws.Cells(iRow, 4).Value = Me.OffcPhNo.Value
ws.Cells(iRow, 8).Value = Me.Amt.Value

'Checkbox validation
Dim ctl As Control
Dim mytext As String
Dim ctrl As Control
Dim SumValue As Integer

'initialise variables
SumValue = 0
mytext = ""

'check that a box is ticked
For Each ctrl In Frame4.Controls
If TypeOf ctrl Is MSForms.CheckBox Then
SumValue = SumValue + ctrl.Value
End If
Next
If SumValue = 0 Then 'no checkboxes ticked
MsgBox "Please select value(s) for Values Requested"
Exit Sub
End If

'combine captions
For Each ctrl In Frame4.Controls
If TypeOf ctrl Is MSForms.CheckBox Then
If ctrl.Value = True Then
Select Case mytext
Case ""
mytext = ctrl.Caption
Case Else
mytext = mytext & ", " & ctrl.Caption
End Select
End If
End If
Next
'populate whatever cell you want.
ws.Cells(iRow, 20).Value = mytext

€˜Fee Reimbursed Option button: Yes
If FeeYes.Value = True Then
ws.Cells(iRow, 17).Value = "Yes"
End If

€˜Fee Reimbursed Option button: No
If FeeNo.Value = True Then
ws.Cells(iRow, 17).Value = "No"
End If

Thanks in Advance

"Bob Bridges" wrote:

I've never used forms in Excel, aside from the occasional command button.
But surely if clicking the Submit button causes data from the form to be
written to the worksheet even if mandatory fields are not filled in, it's
because you wrote the button_click code to do it that way?

I mean, if you look at the Submit_Click code, it must say to take the data
and copy it to the worksheet?

Maybe you'd better show us the part of the code from the button_click
procedure that displays the message AND EXITS THE SUB rather than going on to
fill in the data.

--- "sam" wrote:
On my excel form, I have text boxes, radio buttons,
and check boxes. And I have marked some fields as
mandatory; if users clicks submit button without
filling out these mandatory fields, they will see a
popup msg box asking them to input data in these
fields. The popup msg box works great when user
forgets to input a data in some mandatory field,
BUT the data in excel sheet is populated once the
user clicks submit button(without filling up a
mandatory field). Once I click the OK button on
the msg box and input the data in the mandatory
field and click submit, the data is again populated
in the excel sheet in a new row.