Dirk Goldgar said:
I'm glad to help, though I don't seem to have been much help yet. If
your database is small, you may e-mail me a zipped copy, if you like.
Please first remove any unnecessary data from the copy you intend to
send, then compact it, using Tools -> Database Utilities -> Compact
and Repair Database..., and then use a zip compression utility to
shrink it down to a manageable size. Then send the zip file to the
address you get by removing NO SPAM from the reply-address of this
message.
Valerie -
I've now looked over the database copy you sent me and figured out how
to fix the problem. Let me say right up front that it's not your fault!
Well, only to the extent that you originally had a field named
Date, but you would think that when you renamed it Access would stop
having problems. You'd think that, but you'd be mistaken.
Ken Snell was right about what was going on. I noticed that if I began
editing the form's code module and started typing "Me.Dat", among the
items listed in the intellisense drop-down list was "Me.Date". That
could only mean that Access thought the form had a property or method
named "Date". Of course it doesn't, but when you created the form it
did, because Access creates a property for every control on the form and
every field in the form's recordset. For some reason -- I think we may
safely call it a bug -- Access created this property and didn't destroy
it when you renamed that field.
I found a couple of ways to eliminate the problem. My first approach,
though successful, was more complicated than it needed to be so I won't
describe it in detail (note for Ken: SaveAsText, LoadFromText). Then I
had a much simpler idea, tried it, and it worked: Valerie, here's what
to do:
1. Open the form in Design View.
2. Open the property sheet for the form.
3. On the Data tab, clear the Record Source property, leaving it blank.
4. Save and close the form.
5. Open the form in Design View again.
6. Reset the Record Source property to the table in question; in this
case, LogTable.
7. Save the form.
For me, that fixed it, removing "Date" from the list of form properties.
Once you've done that, you can (and should) go back into the form's code
module and edit the Click event procedure for the command button,
changing it simply to:
Private Sub DateCmd_Click()
'Enters today's date
Me.DateText.SetFocus
Me.DateText = Date
End Sub
If you get the same results I did, this will now work just fine.
By the way, I hope you realize that it's not necessary to set the focus
to DateText before setting its value. I'm assuming you have the
SetFocus line in the event procedure because you really want the focus
to go there, not because you think you have to do that before you can
assign a value to the control.