User form default values ??

Javi

Active Member
Joined
May 26, 2011
Messages
440
Thank you for taking your time to investigate my issue.

I’m having an issue with my user form code after it runs. The first time it runs everything is good however at the end of my code it put default values back in the form for the next entry.

All of the defaults work but the =today() does not. See the below code at very bottom.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
<o:p>This is what the user form shows now =today()
Instead of the correct 11/9/2011
</o:p><o:p></o:p>
Can someone please point me in the right direction to correct this issue.
<o:p> </o:p>
The original defaults are set in userForm_Initialze .
<o:p> </o:p>
Code:
Private Sub UserForm_Initialize()
 
       sdate.Value = Format(Date, "mm/dd/yyyy")
       hours.Value = 4
       part.Value = 2
       
       'make.RowSource = "make1"
       
End Sub
<o:p> </o:p>

<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
Code:
Private Sub CommandButton1_Click()
Dim rNextCl As Range
 
Set rNextCl = Worksheets("Main").Cells(Rows.Count, 2).End(xlUp).Offset(2, 0)
Worksheets("Main").Activate
rNextCl.Select
<o:p> </o:p>
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Main")
<o:p> </o:p>
    'ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    ActiveSheet.Unprotect
<o:p> </o:p>
'find  first empty row in database
iRow = ws.Cells(Rows.Count, 2) _
  .End(xlUp).Offset(1, 0).Row
<o:p> </o:p>
<o:p> </o:p>
If Me.lname = "" Or Me.fname = "" Or Me.year = "" Or Me.make = "" Or Me.model = "" Or Me.wo = "" _
Or Me.sdate = "" Or Me.part = "" Or Me.hours = "" Then
MsgBox ("All Feilds Must be Completed")
<o:p> </o:p>
  Exit Sub
End If
<o:p> </o:p>
With ws
    .Cells(iRow, 2).Value = Me.lname.Value
    .Cells(iRow, 3).Value = Me.fname.Value
    .Cells(iRow, 5).Value = Me.year.Value
    .Cells(iRow, 6).Value = Me.make.Value
    .Cells(iRow, 7).Value = Me.model.Value
    .Cells(iRow, 8).Value = Me.wo.Value
    .Cells(iRow, 9).Value = Me.sdate.Value
    .Cells(iRow, 10).Value = Me.part.Value
    .Cells(iRow, 11).Value = Me.hours.Value
<o:p> </o:p>
    With .Cells(iRow, 1).Resize(1, 7).Borders
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
<o:p> </o:p>
'Add one to column "A" for the line number 
'ws.Cells(iRow, 1).Value = ws.Cells(iRow - 1, 1).Value + 1  
<o:p></o:p> 
<o:p></o:p> 
<o:p> </o:p>
'clear the data and set new defaults
Me.lname.Value = ""
<o:p> </o:p>
Me.fname.Value = ""
<o:p> </o:p>
Me.year.Value = ""
<o:p> </o:p>
Me.make.Value = ""
<o:p> </o:p>
Me.model.Value = ""
<o:p> </o:p>
Me.wo.Value = ""
<o:p> </o:p>
[COLOR=red][B]Me.sdate.Value = "=today()"<o:p></o:p>[/B][/COLOR]
<o:p> </o:p>
Me.part.Value = "2"
<o:p> </o:p>
Me.hours.Value = "4"
<o:p> </o:p>
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    'ActiveSheet.Unprotect
End With
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Use the same code as you used in the UserForm_Initialize procedure.

sdate.Value = Format(Date, "mm/dd/yyyy")
 
Upvote 0

Forum statistics

Threads
1,216,218
Messages
6,129,571
Members
449,518
Latest member
srooney

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