I have a bound subform. When I open the the form I get the last row on the table. If I open the form with "DoCmd.GoToRecord , , acNewRec" I get a blank form. If I do not fill in the form for any reason and mouse off the subform, I end up with a blank row with nothing but the date which is put in when the date field loses focus and is unfilled. For clarification, in the form open I set focus to the date field.
TIA
Access 2003 Blank rows created
-
- 2StarLounger
- Posts: 125
- Joined: 17 Feb 2010, 16:25
Access 2003 Blank rows created
PaulW
Lost Wages, NV USA
(former Cobol Programmer)
Lost Wages, NV USA
(former Cobol Programmer)
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access 2003 Blank rows created
Do you mean that you have code that fills the date field? If so, could you post it?
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 125
- Joined: 17 Feb 2010, 16:25
Re: Access 2003 Blank rows created
Private Sub frm485Date_LostFocus()
If IsNull(frm485Date) Or IsEmpty(frm485Date) Then
frm485Date = CLng(Date)
End If
End Sub
If IsNull(frm485Date) Or IsEmpty(frm485Date) Then
frm485Date = CLng(Date)
End If
End Sub
PaulW
Lost Wages, NV USA
(former Cobol Programmer)
Lost Wages, NV USA
(former Cobol Programmer)
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access 2003 Blank rows created
Such code is dangerous because it will fill the date automatically.
Under normal circumstandes, if you're on a new record it will actually be created only when you start entering data, so if you don't enter data no record will be saved. But your code enters data automatically, causing the new record to become "real".
If you have an AutoNumber primary key in the record source of the subform, you can test the value of this key - it will be Null until the user enters data. If the AutoNumber field is named ID, you could use
Under normal circumstandes, if you're on a new record it will actually be created only when you start entering data, so if you don't enter data no record will be saved. But your code enters data automatically, causing the new record to become "real".
If you have an AutoNumber primary key in the record source of the subform, you can test the value of this key - it will be Null until the user enters data. If the AutoNumber field is named ID, you could use
Code: Select all
Private Sub frm485Date_LostFocus()
If IsNull(Me.frm485Date) And Not IsNull(Me.ID) Then
Me.frm485Date = CLng(Date)
End If
End Sub
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 125
- Joined: 17 Feb 2010, 16:25
Re: Access 2003 Blank rows created
Thank you again and again and again. That seems to have fixed my problem.
If you ever get to Las Vegas, Carol and I would like to take you to dinner.
If you ever get to Las Vegas, Carol and I would like to take you to dinner.
PaulW
Lost Wages, NV USA
(former Cobol Programmer)
Lost Wages, NV USA
(former Cobol Programmer)
-
- Administrator
- Posts: 78488
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Access 2003 Blank rows created
Thank you for the offer!
(No idea if/when I'll be in Las Vegas)
(No idea if/when I'll be in Las Vegas)
Best wishes,
Hans
Hans