Why 1st Record shows ($0.00) when open a Form?

KarenYT
3StarLounger
Posts: 212
Joined: 28 Mar 2011, 18:29
Location: Netherlands

Why 1st Record shows ($0.00) when open a Form?

Post by KarenYT »

Something I don't understand -
When I open the Form (frm03AddPrice) to add a new record, the first records displays the Unit_Price as a minus 1 ? (i.e. ($1.00))

I have created a command button using a macro for the users to add a new record, there's no problem for that. Yet I want to know what's the reason for having ($1.00) when I open the Form. What have I done wrong ?

Please see attached database for better clarification.
Appreciate your reply please.

thanks.
Karen
You do not have the required permissions to view the files attached to this post.

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

Re: Why 1st Record shows ($0.00) when open a Form?

Post by HansV »

Unless otherwise specified, a form opens to the first record of its record source.

The first record of the 00PriceList table looks like a kind of dummy record:
S0878.png
The PART_NUMBER and NOMEN fields contain text resembling the field names, and UNIT_PRICE contains ($1.00) i.e. -1.

Would it be OK to remove that record, or do you need it for anything?

BTW, it's possible to make a form open to a new record automatically, if you wish.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

KarenYT
3StarLounger
Posts: 212
Joined: 28 Mar 2011, 18:29
Location: Netherlands

Re: Why 1st Record shows ($0.00) when open a Form?

Post by KarenYT »

The reason I have to create a dummy record because of the -1.
Yes, the 1st record is supposedly not there.
==
Would it be OK to remove that record, or do you need it for anything?
No, I don't need it, the 1st record keeps coming back with -1 ???
Please elaborate a bit to me, thanks.

BTW, it's possible to make a form open to a new record automatically, if you wish.
Yes, is it like :

Me.AllowEdits = Me.NewRecord
Me.AllowDeletions = False

KarenYT
3StarLounger
Posts: 212
Joined: 28 Mar 2011, 18:29
Location: Netherlands

Re: Why 1st Record shows ($0.00) when open a Form?

Post by KarenYT »

Oh, by the way, actually the dummy Part_Number carries a $0.00, it becomes ($1.00) once the form has opened once.

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

Re: Why 1st Record shows ($0.00) when open a Form?

Post by HansV »

Oh, I see now. The On Current event of the form contains the line

Me!UNIT_PRICE = Not Me.NewRecord

This should probably be

Me!UNIT_PRICE.Locked = Not Me.NewRecord

If you only want to use the form to add new records, you can set its DataEntry property to Yes.
If you want to be able to view and edit existing records, but start on a new record, you can use

Code: Select all

Private Sub Form_Load()
    On Error Resume Next ' to suppress error if there are no records yet
    RunCommand acCmdRecordsGoToNew
End Sub
Best wishes,
Hans

KarenYT
3StarLounger
Posts: 212
Joined: 28 Mar 2011, 18:29
Location: Netherlands

Re: Why 1st Record shows ($0.00) when open a Form?

Post by KarenYT »

Ah, what a stupid mistake I had ! (Late now 12.30 am !)
Thanks a million, Hans !

The other option is very useful for me too ! I will try this one!
Thanks very much again !