random dates showing up in userform

I

incidental

Hi

I was wondering if someone could help me out a little as I think I am
going to go completely crazy if I spend another minute scanning through
the archives in these groups.

My problem is that I have a user form that I use to view and edit data
on and excel spreadsheet. There are 15 textboxes most of which are
dates and 2 comboboxes that all hold different data. I have the form
set up to view all the fields but I only let 10 of the textboxes and
the two combo boxs be amended as the other five textboxes run formulas
from the data that can be entered. My problem is that when I view the
data in the userform any of the cells that have nothing entered into
them show up in the form with the date 30/12/1899. Does anyone know
why the absence of data in these cells would show up as the given date
when I view the userform???

Any help would be great as I can't seem to find anything like this in
the group posts. I have included the code I have been using on the
userform in question which is probably the problem but I am pretty much
try to learn vba from the net so I hope you can cut me some slack for
any really bad code : )

Here is the code

Private Sub Cmdcancel_p_Click()
Unload Me
Ufmfrontdesk.MultiPage1.Value = 2
Ufmfrontdesk.Show vbModal
End Sub

Private Sub Cmdfind_p_Click()
On Error GoTo errorhandler
Worksheets("primary").Range("a1:a100").Select
Selection.Find(what:=Me.Txtname_p.Text, after:=ActiveCell,
LookIn:=xlValues, _
lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, _
MatchCase:=False).Activate
Me.Txtname_p.Value = ActiveCell
Me.Txtref_p.Value = ActiveCell.Offset(0, 1)
Me.Txtfirstday_p.Value = FormatDateTime(ActiveCell.Offset(0, 2),
vbShortDate)
Me.Txtlastday_p.Value = FormatDateTime(ActiveCell.Offset(0, 3),
vbShortDate)
Me.Txtguidancedate_p.Value = FormatDateTime(ActiveCell.Offset(0,
4), vbShortDate)
Me.Txtnotificationdate_p.Value =
FormatDateTime(ActiveCell.Offset(0, 5), vbShortDate)
Me.Txtdepositdue_p.Value = FormatDateTime(ActiveCell.Offset(0, 6),
vbShortDate)
Me.Txtdeposited_p.Value = FormatDateTime(ActiveCell.Offset(0, 7),
vbShortDate)
Me.Txtppldue_p.Value = FormatDateTime(ActiveCell.Offset(0, 8),
vbShortDate)
Me.Txtpplissued_p.Value = FormatDateTime(ActiveCell.Offset(0, 9),
vbShortDate)
Me.Txtreportdue_p.Value = FormatDateTime(ActiveCell.Offset(0, 10),
vbShortDate)
Me.Txtreportissued_p.Value = FormatDateTime(ActiveCell.Offset(0,
11), vbShortDate)
Me.TxtpublishDue_p.Value = FormatDateTime(ActiveCell.Offset(0, 12),
vbShortDate)
Me.Txtpublished_p.Value = FormatDateTime(ActiveCell.Offset(0, 13),
vbShortDate)
Me.Cmbfollowup_p.Value = ActiveCell.Offset(0, 14)
Me.Cmbgrade_p.Value = ActiveCell.Offset(0, 15)
Me.Txtcomments_p.Value = ActiveCell.Offset(0, 16)
Exit Sub
errorhandler:
MsgBox "No Report Found", vbOKOnly, "Report Not Found"
Call UserForm_Initialize
End Sub

Private Sub Cmdsave_p_Click()
ActiveCell.Value = Txtname_p.Value
ActiveCell.Offset(0, 1) = Txtref_p.Value
ActiveCell.Offset(0, 2) = Txtfirstday_p.Value
ActiveCell.Offset(0, 3) = Txtlastday_p.Value
ActiveCell.Offset(0, 5) = Txtnotificationdate_p.Value
ActiveCell.Offset(0, 7) = Txtdeposited_p.Value
ActiveCell.Offset(0, 9) = Txtppldate_p.Value
ActiveCell.Offset(0, 11) = Txtreportissued_p.Value
ActiveCell.Offset(0, 13) = Txtpublished_p.Value
ActiveCell.Offset(0, 14) = Cmbfollowup_p.Value
ActiveCell.Offset(0, 15) = Cmbgrade_p.Value
ActiveCell.Offset(0, 16) = Txtcomments_p.Value
End Sub

Private Sub UserForm_Initialize()
Txtname_p.Text = ""
Txtref_p.Text = ""
Txtfirstday_p.Text = ""
Txtlastday_p.Text = ""
Txtguidancedate_p.Text = ""
Txtnotificationdate_p.Text = ""
Txtdepositdue_p.Text = ""
Txtdeposited_p.Text = ""
Txtppldue_p.Text = ""
Txtpplissued_p.Text = ""
Txtreportdue_p.Text = ""
Txtreportissued_p.Text = ""
TxtpublishDue_p.Text = ""
Txtpublished_p.Text = ""
Cmbfollowup_p.List = Array("", "Yes", "No")
Cmbfollowup_p.ListIndex = 0
Cmbgrade_p.List = Array("", "1", "2", "3", "4")
Cmbgrade_p.ListIndex = 0
Txtcomments_p.Text = ""
End Sub



thanks for looking
 
D

Dave Peterson

If the cell is empty, excel will treat it as 0. And if you do this:

msgbox FormatDateTime(0,vbShortDate)

You'll see December 30, 1899.

Maybe you should check to see if the cell is empty or greater than 0 before you
populate the textbox.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top