View Full Version : Only show a form for NEW items
ukdane
12-14-2009, 01:28 AM
I know it can be done, I just can't remember how....
.... from the switchboard, when the user presses the "Add new Data" button, none of the old records are shown, only the new record should be visible.
All new records should be visible, UNTIL the user presses an "update" data button, at which point ONLY theempty new record fields should be visisble.
Thanks
DoCmd.OpenForm ("Latest Status of Projects"),,,,acFormAdd
Imdabaum
12-23-2009, 01:36 PM
Is there a way to identify if you're on the last record? I'm trying to enforce the users to use the NEW button to create records. I find that often they hit the next navigation button and advance to 2-10 new records. Customer doesn't want to hide the form from them if there are no values, but I want to restrict them from making additions through the next button.
Something like
dim rs as DAO.Recordset
Set rs = Form.Recordset
if rs.OnLastrecord Then
Do Nothing
else
DoCmd.goto ,,acNext
End if
let me know if that doesn't make sense.
ALSO as a side note... is there anyway to change the settings so the button wizards don't embed the code as a macro? I like to organize my code and don't fancy the embedded macros. (You may criticize me if you likefootinmout)
geekgirlau
12-23-2009, 05:19 PM
What version are you using? In 2003 once a user goes to a new record, they can't progress any further using the navigation buttons until they actually make some changes.
Also I've never seen the wizards use a macro - they default to VBA code, not macros. AFAIK there is no way to change this.
ukdane
12-23-2009, 06:52 PM
If I understand you correctly, can you use the function to count the total number of records, and check if it is the same as the current record. If it is the same then you are on the last field, so you could hide the next record button, and if it isn't the same then you show the next record button.
Edit: I think you'd need to put the code into the before update event of the form.
Replace the navigation Buttons with custom built ones ( the code can be in Modules if you must and called from the button).
In the on Current event of the form enter this code
Dim rs As Object, Records As Integer
Set rs = Me.Recordset.Clone
If Not Me.NewRecord Then
Me.Next.Visible = Not (rs.EOF) ' next record
rs.Bookmark = Me.Bookmark
rs.MovePrevious
Me.Command36.Visible = Not (rs.BOF) ' Previous Record
Me.Command37.Visible = Not (rs.BOF) ' First Record
rs.MoveNext
Me.Command38.Visible = True ' Last Record
me.command39.visible = True ' new record
else
me.command39.visible = False ' new record
End If
rs.Close
Set rs = Nothing
Imdabaum
01-07-2010, 11:05 AM
What version are you using? In 2003 once a user goes to a new record, they can't progress any further using the navigation buttons until they actually make some changes.
Also I've never seen the wizards use a macro - they default to VBA code, not macros. AFAIK there is no way to change this.
Access 2007 seems to default everything to the bloody embedded macros.
Replace the navigation Buttons with custom built ones ( the code can be in Modules if you must and called from the button).
In the on Current event of the form enter this code
snip....
Thanks OBP. I'll give that a try.
I changed a few things to fit the buttons I was using and finally figured out that me.command38 wasn't the same button I was using and walla. Thanks. I had tried something similar to that on the cmdNext button. But it never registered whether the record was new.
I don't know if it's worth it to post, but here is the code that didn't work.
Private Sub cmdNext_Click()
DoCmd.GoToRecord , , acNext
If Me.NewRecord Then
DoCmd.CancelEvent
End If
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.