Access 2003 Blank rows created

PaulW
2StarLounger
Posts: 125
Joined: 17 Feb 2010, 16:25

Access 2003 Blank rows created

Post by PaulW »

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
PaulW
Lost Wages, NV USA
(former Cobol Programmer)

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Access 2003 Blank rows created

Post by HansV »

Do you mean that you have code that fills the date field? If so, could you post it?
Best wishes,
Hans

PaulW
2StarLounger
Posts: 125
Joined: 17 Feb 2010, 16:25

Re: Access 2003 Blank rows created

Post by PaulW »

Private Sub frm485Date_LostFocus()
If IsNull(frm485Date) Or IsEmpty(frm485Date) Then
frm485Date = CLng(Date)
End If

End Sub
PaulW
Lost Wages, NV USA
(former Cobol Programmer)

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Access 2003 Blank rows created

Post by HansV »

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

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

PaulW
2StarLounger
Posts: 125
Joined: 17 Feb 2010, 16:25

Re: Access 2003 Blank rows created

Post by PaulW »

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.
PaulW
Lost Wages, NV USA
(former Cobol Programmer)

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Access 2003 Blank rows created

Post by HansV »

Thank you for the offer! :thankyou:

(No idea if/when I'll be in Las Vegas)
Best wishes,
Hans