form issue. (1 Viewer)

2ippy

Newbie Here, Be gentle.
Local time
Today, 15:37
Joined
Nov 10, 2006
Messages
78
I am using VBA on a button to transfer customerID to this form and it's auto generates a ItemID.

Problem is that it's making a record b4 anything is entered. Is there a way to make the record be made later rather than instantly, just in case someone opens this form?
 

rat_b76

Registered User.
Local time
Tomorrow, 00:37
Joined
May 20, 2003
Messages
37
Hi,

Post the code you have associated to your button, this will give people more of an idea about what is happening with the Button Click event.

Cheers

rat_b76
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
When you open a bound form and insert the customer ID in it to start with, it has just created a new record. But, you can back it out by using
Code:
Me.Undo
on the BeforeUpdate event, if you want to back it out should the form not be filled in completely or certain fields not filled out.

If you want to avoid using up an autonumber, then you would likely need to use an UNbound form and use SQL in conjunction with code to make the addition.
 

2ippy

Newbie Here, Be gentle.
Local time
Today, 15:37
Joined
Nov 10, 2006
Messages
78
thx, so how would i use a cancel button in the form so that it don't create the record even though it does coz you've opened the form?
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
If you want to use a cancel button, you can put this code in the ON Click event of that button:
Code:
Me.Undo
DoCmd.CloseForm acForm, Me.Name, acSaveNo
 

2ippy

Newbie Here, Be gentle.
Local time
Today, 15:37
Joined
Nov 10, 2006
Messages
78
ok getting compile error, was i ment to replace part of that code with a form name?
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
shouldn't have to. What part does it highlight?
 

2ippy

Newbie Here, Be gentle.
Local time
Today, 15:37
Joined
Nov 10, 2006
Messages
78
.CloseForm

what is the Me.name for ?
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
Me.Name is a coding shortcut that is the same as using the explicit form name, but Me refers to the form that the event that you are coding is on. It makes it easy to copy and paste between forms without having to change code to the actual name and if you change the name of a form the code is still relevant.
 

2ippy

Newbie Here, Be gentle.
Local time
Today, 15:37
Joined
Nov 10, 2006
Messages
78
Code:
DoCmd.CloseForm acForm, Me.Name, acSaveNo

doesn't like the closeform and it's not in the objects browser.

Correct code...

Code:
DoCmd.Close acForm, Me.Name, acSaveNo

?
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
yep, sorry - sometimes my brain gets in the way of my typing (I knew that, but for some reason it didn't make it through the gray matter).
 

2ippy

Newbie Here, Be gentle.
Local time
Today, 15:37
Joined
Nov 10, 2006
Messages
78
well that code works i guess as it should but the item record is still being created.
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
with Me.Undo it shouldn't be. Are you sure it's being created and not that the autonumber is not just incrementing? Because the autonumber WILL increment regardless of whether you cancel or not. It does it when you put anything into the field (including if you use a "default") and even if you cancel it is lost forever.
 

2ippy

Newbie Here, Be gentle.
Local time
Today, 15:37
Joined
Nov 10, 2006
Messages
78
yeah the item is autonumbered and the autonumber for that customer is copied into the item form to link them.
 

boblarson

Smeghead
Local time
Today, 07:37
Joined
Jan 12, 2001
Messages
32,059
If you are trying to create an item in one form and then details in another form and you don't want the item on the first form created then the code should be (for the cancel button on the details form):
Code:
Me.Undo
Forms!YourFirstFormName.Undo
DoCmd.Close acForm, Me.Name, acSaveNo

But, you'll still have the issue about the autonumber that is incrementing regardless.
 

Users who are viewing this thread

Top Bottom