Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if new record on form 2

Status
Not open for further replies.

Jonmit

Programmer
Aug 28, 2009
6
AU
I want to check if the current record on a form is a new record or not and then take appropriate action. At the moment in the 'On current' event property i allocate the value of a text box to variable,which i use on another form. This works fine until i go to a new record and there is nothing in the text box. I have found in the help pages the 'NewRecordMark' sub but i cant work out how to insert it into the code i have to test for a new record and bypass the code for setting the variable. This is the sub:

Sub NewRecordMark(frm As Form)
Dim intnewrec As Integer

intnewrec = frm.NewRecord
If intnewrec = True Then
MsgBox "You're in a new record." _
& "@Do you want to add new data?" _
& "@If not, move to an existing record."
End If
End Sub

It doesnt seem to matter how i insert it into the 'oncurrent' event it always comes up with an error

Any help on this will be greatly appreciated
John
 
As you are using the CurrentEvent, why not simply check there?

Code:
Private Sub Form_Current()
If Me.NewRecord Then
    MsgBox "New record"
Else
    MsgBox "Existing record"
End If
End Sub



 
How are ya Jonmit . . .
Code:
[blue]   If Not Me.NewRecord Then
      [green]'your code to update the textbox[/green]
   End If[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thank you both. So simple. I must have tried everything but the simplest. Another little issue if you happen to look back here. The text box i am setting the variable from is actually an autonumber. When i am on a new record does the after update, on the autonumber text box, kick in straight after the number is generated or does it not happen until after you leave the record. I have put a breakpoint in the code straight after the variable is supposed to be set only to find it has no value and the breakpoint doesnt happen. Would i be better to use the 'after update' of another text box that you physically enter data into to set the variable, in the instance of a new record. i need the autonumber value as an index for another form/table.
Hoping to thank you again
John
 
A large number of events in Access are not triggered by programmatic updates of controls, only by manual updates, so if you wish to use an update event, set it on a manual control or the form itself.

 
Thanks again. That is handy to know. I did change the 'after update' to a manual text box and it seems to be working fine now. I know i am being a bit painfull but there now happens to be another thing i dont know why is happening. It concerns the 2 forms/tables i am dealing with but different problem.
The 1st form/table is for grain delivery records.
2nd form/table is for grain sales.
On the grain delivery form i have a button that opens the grain sales form to a new record and can enter sale details of that load of grain straight away. Also on the delivery form is a 'Sold' check box which marks it as sold and also the code i have been working with in previous discussion puts the 'grain sale' ID in a SaleID in the delivery form/table. After this happens i requery the 'grain sale' form as i have a condensed version of the delivery form as a subform there.When this event happens nothing changes, although i can see it requeries as the form flickers. If i enter another load for that grain sale then when it requeries the previous record shows on subform etc etc. The subform on the 'grain sale' form is always one record behind. Even if i untick the check box to reverse the sale the subform is always one record behind? If i use the navigation buttons and go back one record on 'grain sale' form and then forward one record then the subform corrects itself. Is there another way of requerying, or something, the 'grain sale' form, like the navigation buttons, to keep the subform in sinc with what i am doing?
Hope you can help again
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top