Help for Save Button On a Form (1 Viewer)

yameen2011

Registered User.
Local time
Today, 07:58
Joined
Jan 19, 2013
Messages
59
Hi friends i am working on a database and i have notice after making a form that when i enter a record using a form if i enter incomplete data on the form access automaticaly save that record and generate a id for that record.
For example i have a table that contain
StudentID,StdName,FatherName,DOB,Adress,Phone

and i have created a form for that table that also containing these fields.
Here i want to do that on the form i want a "Save" button , and the purpose of this button that when i click on this button then MS Access Save the record and then generate the ID for that record and if i close my form without pressing "SAVE"
button access do not save that incomplete record.
Is there any procedure to perform this any suggestion .????
Waiting......
 

Mihail

Registered User.
Local time
Today, 06:58
Joined
Jan 22, 2011
Messages
2,373
In order to not allow the incomplete records to be saved, you should define what is named "incomplete".

For example, a record for a person:
PersonName, PhoneNumber
While each person has a name, not each person has a phone.
So, the PersonName field should have the Required property set to Yes and the PhoneNumber field should have the same property set to No.

If you do that, Access will never save a record until the user will fill ALL fields that have the Required property set to Yes.
 

yameen2011

Registered User.
Local time
Today, 07:58
Joined
Jan 19, 2013
Messages
59
Dear Mihail, thanks for replying ,
But basicaly i want to create a save button on the form that is used only for saving record to the table, for example i am entering a new student to my student table , if i enter student name and any other detail then suddenly i decided to close the form , and i click on close button to close form , but record is saved to the student table, and student id also generated , to avoid this i want a "Save" button for my form , that is use only for saving record to the table.any vb code or macro or any technique kindly guide me....
 

Mihail

Registered User.
Local time
Today, 06:58
Joined
Jan 22, 2011
Messages
2,373
Even if you don't say, I'm sure that your problem is the gaps between IDs.
Should not be.
Access is the single "user" of this numbers.
And should be the single one that "see" and use this numbers.

In order to use a SAVE button, the form should be unbounded, and this:
Recordsets for Beginners - Access wiki - Access Help and How-to - Microsoft Office by UtterAccess.com
should be used.

But, one more time: DO NOT DO THIS.
Eventually create an UNDO button:
Private Sub UndoButton_Click()
Me.Undo
End Sub
 

yameen2011

Registered User.
Local time
Today, 07:58
Joined
Jan 19, 2013
Messages
59
thanks for help but
my question is that is it possible to disable automatic saving in access?
 

sensetech

An old, bold coder
Local time
Today, 04:58
Joined
May 1, 2009
Messages
41
1. In Form properties, set 'Close button' to false

2. Add a CANCEL button with code something like this behind it:

If Me.Dirty Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End if

DoCmd.Close
 

Mihail

Registered User.
Local time
Today, 06:58
Joined
Jan 22, 2011
Messages
2,373
thanks for help but
my question is that is it possible to disable automatic saving in access?
Both YES or NO answers are available.
NO if you use a bounded form.
YES but you need to use an unbounded form and a lot of programming in order to save the record.
 

yameen2011

Registered User.
Local time
Today, 07:58
Joined
Jan 19, 2013
Messages
59
1. In Form properties, set 'Close button' to false

2. Add a CANCEL button with code something like this behind it:

If Me.Dirty Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End if

DoCmd.Close

Working but now i am facing another problem with my form where i have applied this code,
i have coded my form as when i leave blank my form and click on close button then form is asking again and again to put values in required fields.

Here is my form coding:
Code:
Private Sub GLcode_AfterUpdate()
GLdscp = DLookup("Description", "tblAccounts", "Glcode=" & GLcode)
End Sub

Private Sub GLcode_BeforeUpdate(Cancel As Integer)
If IsNull(DLookup("Glcode", "tblAccounts", "GLcode=" & Forms!frmTransaction!GLcode)) Then

MsgBox "Please enter Valid GL Code..."
Cancel = True

End If
End Sub


Private Sub GLcode_LostFocus()
If IsNull(Me!GLcode) Then

MsgBox "You must enter a GL Code!"

DoCmd.GoToControl ("TranxTypeID")
DoCmd.GoToControl ("GLcode")

End If
End Sub

Private Sub TranxTypeID_AfterUpdate()
Tranxdscp = DLookup("TranxType", "tblTranxType", "TranxTypeID=" & TranxTypeID)
End Sub
Private Sub cmdsave_Click()
On Error GoTo Err_cmdsave_Click


    DoCmd.RunCommand acCmdSaveRecord

Exit_cmdsave_Click:
    Exit Sub

Err_cmdsave_Click:
    MsgBox Err.Description
    Resume Exit_cmdsave_Click
    
End Sub
Private Sub cmdundo_Click()
On Error GoTo Err_cmdundo_Click


    DoCmd.RunCommand acCmdUndo

Exit_cmdundo_Click:
    Exit Sub

Err_cmdundo_Click:
    MsgBox Err.Description
    Resume Exit_cmdundo_Click
    
End Sub

Private Sub TranxTypeID_BeforeUpdate(Cancel As Integer)
If IsNull(DLookup("TranxTypeID", "tblTranxType", "TranxTypeID=" & Forms!frmTransaction!TranxTypeID)) Then

MsgBox "Please enter Valid Transaction Type"
Cancel = True

End If
End Sub


Private Sub TranxTypeID_LostFocus()
If IsNull(Me!TranxTypeID) Then

MsgBox "You must Enter Transaction Type...!"

DoCmd.GoToControl ("TranxAmountD")
DoCmd.GoToControl ("TranxTypeID")

End If
End Sub
 

sensetech

An old, bold coder
Local time
Today, 04:58
Joined
May 1, 2009
Messages
41
There shouldn't be a standard close option any longer (step 1 in my original post) or do you mean your custom SAVE button? if so, what code do you have behind that? And are you auto-populating any fields when the form loads?
 

yameen2011

Registered User.
Local time
Today, 07:58
Joined
Jan 19, 2013
Messages
59
Yes i want a custom save button and now issue is resolved butt now i have this issue.
when open form as enter new record and then you click on close button you will see the messages , put values in the fields, here i want that while pressing close button access close the form.
Here is a sample attached.
 

Attachments

  • Sample.zip
    41.3 KB · Views: 86

sensetech

An old, bold coder
Local time
Today, 04:58
Joined
May 1, 2009
Messages
41
All the validation should appear in the Click event for the Save button rather than in the events behind the bound controls. Do that and life will become much simpler.
 

Users who are viewing this thread

Top Bottom