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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie qustion on adding data thru form 2

Status
Not open for further replies.

NVSbe

Programmer
Sep 9, 2002
153
BE
Okay, so I have this bound form with a couple of textfields in it. When someone presses on the "new" button, it'll

DoCmd.gotoRecord , , acNew

and display an "OK" and a "Cancel" button. Now, my question is, it seems it inserts the data in the table as soon as you type, so how can I get my cancel button to work?

(The same question would go for the "Update" button,but I'll worry about that later)

Thanks for your help,
Niki

--------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
Try and place your code on then forms - before update event - if the user pushes the cancel button then set cancel = true.
Do not forget to go back to where the user came from.

Herman
 
Well...

When I press cancel this way, it seems the changes are still kept, but in a separate recordset (does this make sense) because my navigation buttons won't work any more then... --------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
You may have placed the cancel = true wrongly on your form and one of the fields in your table on this form is set to required = yes.

Fiddle a bit with the placement of the "cancel=true" line it should do the trick. ;-)

Herman
 
No, that's not it. I don't have anything set to required=yes...

Lemme show abit more of my code:

'Add
Private Sub cmdInvoegen_Click()
DoCmd.GoToRecord , , acNewRec

Me("txtskill").SetFocus
Call setText(True) 'enables textfields
Call setCommands(False) 'disables buttons
End Sub

'OK
Private Sub cmd2OK_Click()
Me("txtskill").SetFocus
Call setText(False)
Call setCommands(True)
pushedCancel = False

DoCmd.GoToRecord , , acLast
Me.Requery
Call protectbuttons
End Sub


'Cancel
Private Sub cmd2Cancel_Click()

pushedCancel = True
Call Form_BeforeUpdate(0)
Me("txtskill").SetFocus
Call setText(False)
Call setCommands(True)

End Sub


'Form_AfterUpdate
Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = pushedCancel
If Cancel = True Then
DoCmd.CancelEvent
End If
End Sub

--------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
Oh... and with navigation buttons, I don't mean the standard ones... They're disabled. I mean regular buttons, to go through the records... :/ --------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
This is set on the button on the form and, as I can not see what settext and setcommands are doing, I think that I have an idear and should be placed after the cancel on the before update event.

As I see it the reason that your navigation buttons does not work is that you have disabled them by using Call setCommands(False) 'disables buttons.


Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = pushedCancel
If Cancel = True Then
DoCmd.CancelEvent
else
Call setText(True) 'enables textfields
Call setCommands(False) 'whey this ?
End If
End Sub

Herman
 
This is getting nowhere... I think I'm gonna stick with the standard Access input screens... I'm going home now, but if there's any more suggestions, I'll look at em tomorrow. Thank you so muchfor your help so far... :)

Niki --------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
Ok Niki....

Dont you cry now - it happens to us all :-D

Lets talk again 2morrow and we will seen how it gows then.

Sleep Well ;-)
 
Yes, let's talk :)

I am understanding the problem a bit better now, and the main problem is:

When I leave a bounded textfield, it seems to insert that field into the table already, so when I then press cancel, I can do whatever I want, the data will still be in the table... Can't you tell the form to wait with inserting until someone presses OK? --------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
If your form has not updated the new record (i.e. requery/move next etc.) the user is able to hit the ESC key and this record is never recorded (so to say)

But in your code it looks like you run a series of requery and updates on your form, so this code updates your record in your table.

You have 2 solutions as I see it.

1. Step thru your code (F8) and figure out where the record is updated, by keeping an eye on your tbl and hitting the shift-F9 keys (requery the tbl that you are looking at without close/open) and then correcting your code so that you do not update before YOU want to. And this is the correct way to do it.

2. The quick and dirty solution: If your user hits the ESC button - delete the record!
Use keycode to find out if your user has hit the ESC.
However this is not a nice way to do it and will land you in a new problem..... if your user, by accident, hits ESC a record is deleted - not good.

Also there is one more solution - zip the whole thing and mail it to me and I will have a look at it, and see what I can do ;-)

Herman
 
Hmm.... just got back from my boss...

We're going to do it differently, without bound items...

Thanks a lot for your help, I'll give you a star or two for your patience with me, and for the really helpfull suggestions. --------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
The line you are missing is:
Me.Undo

This will undo any changes you have made, including adding the new record:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If pushedCancel = True Then
Cancel = true
[red]me.Undo[/red]
else
Call setText(True) 'enables textfields
Call setCommands(False) 'whey this ?
End If
End Sub
----------------------------------------
Ben O'Hara
----------------------------------------
 
Heh.. isn't this just my luck... Finding it right after i's decided it isn't going to be used?

Anyway, the two last posts combined worked, so the me.undo and then checking to see if any updates were made...

You guys are the best, thank you so much for helping...

Niki --------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
By the way, this was the code needed for the Before_Update event, if you're interested...


Private Sub Form_BeforeUpdate(Cancel As Integer)
Cancel = pushedCancel
If Cancel = -1 Then
Me.Undo
pushedCancel = False
DoCmd.CancelEvent
End If
End Sub
--------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top