I have built a form to enter new members and add them to the members table. The record source for the form is a query that pulls the fields from the members table (name, address etc.) that I need for each new member, where the first field value = null:
AddNewMemberQ:
(MemberID is excluded from the form, it is the unique index for each member)
My problem is on the form. I have a command button to save the entered data and it needs to clear the form so if there is another new member to enter the user can do so.
Right now I have tried many different things to get the command button to both save the data and clear the fields. Depending on what I have tried, the entered data gets saved to the member table either after closing and opening the form, or after clicking “refresh” on the Access ribbon, which will not be available after I split the database to protect the backend from inadvertent end-user changes.
I do know that after clicking the button the data is still “dirty” indicated by the pencil icon in Access. A previous issue, also with a form command button, I just had to start the sub routine with:
I try to keep track of all the possible combinations that I try, and the results. But I am not a programmer or a coder, and I eventually get lost in all the possible combinations. Some of what I have tried includes:
----------------------------------
saves record if form is closed:
--------------------------------------
saves record, doesnt clear form:
---------------------------------------
works if close AddNewMember (form) and hit refresh in the ribbon:
-------------------------------------
---------------------------------------
------------------------
Hope I got the duplicates out…I do realize some of the above examples are without the sub routine start and end statements, for clarification.
Some of the things I have tried come from several searches on this forum.
AddNewMemberQ:
Code:
[COLOR=#1f497d][COLOR=#1f497d]SELECT Members.LastName, Members.FirstName, Members.Address, Members.City, Members.State, Members.ZIP, Members.MemberID, Members.Phone, Members.CellPhone, Members.SignInSheetPosition[/COLOR]
[COLOR=#1f497d]FROM Members[/COLOR]
[COLOR=#1f497d]WHERE (((Members.LastName) Is Null));[/COLOR]
[/COLOR]
My problem is on the form. I have a command button to save the entered data and it needs to clear the form so if there is another new member to enter the user can do so.
Right now I have tried many different things to get the command button to both save the data and clear the fields. Depending on what I have tried, the entered data gets saved to the member table either after closing and opening the form, or after clicking “refresh” on the Access ribbon, which will not be available after I split the database to protect the backend from inadvertent end-user changes.
I do know that after clicking the button the data is still “dirty” indicated by the pencil icon in Access. A previous issue, also with a form command button, I just had to start the sub routine with:
Code:
[COLOR=#1f497d][COLOR=#1f497d]DoCmd.RunCommand acCmdRefresh[/COLOR]
[/COLOR]
Code:
[COLOR=#1f497d][COLOR=#1f497d]Private Sub SaveNewMember_Click()[/COLOR]
[COLOR=#1f497d]If Form.Dirty Then Form.Dirty = False[/COLOR]
[COLOR=#1f497d]If Not Form.NewRecord Then Form.NewRecord - (I think the VB editor complained about this one, tried it anyhow)[/COLOR]
[COLOR=#1f497d]End If[/COLOR]
[COLOR=#1f497d]End Sub[/COLOR]
[/COLOR]
saves record if form is closed:
Code:
[COLOR=#1f497d][COLOR=#1f497d]DoCmd.RunCommand acCmdSaveRecord[/COLOR]
[COLOR=#1f497d] DoCmd.Close[/COLOR]
[COLOR=#1f497d] Form.RecordSource = "AddNewMemberQ"[/COLOR]
[COLOR=#1f497d] Me.Requery[/COLOR]
[COLOR=#1f497d] Me.Refresh[/COLOR]
[/COLOR]
saves record, doesnt clear form:
Code:
[COLOR=#1f497d][COLOR=#1f497d]DoCmd.RunCommand acCmdSaveRecord[/COLOR]
[COLOR=#1f497d]DoCmd.GoToRecord , , acNewRec[/COLOR]
[/COLOR]
works if close AddNewMember (form) and hit refresh in the ribbon:
Code:
[COLOR=#1f497d][COLOR=#1f497d]Private Sub SaveNewMember_Click()[/COLOR]
[COLOR=#1f497d]If Me.Dirty Then Me.Dirty = False[/COLOR]
[COLOR=#1f497d] If Not Me.NewRecord Then[/COLOR]
[COLOR=#1f497d] DoCmd.RunCommand acCmdRecordsGoToNew[/COLOR]
[COLOR=#1f497d]End If[/COLOR]
[COLOR=#1f497d]End Sub[/COLOR]
[/COLOR]
Code:
[COLOR=#1f497d][COLOR=#1f497d]Private Sub SaveNewMember_Click()[/COLOR]
[COLOR=#1f497d]DoCmd.RunCommand acCmdRefresh[/COLOR]
[COLOR=#1f497d]If Me.Dirty Then Me.Dirty = False[/COLOR]
[COLOR=#1f497d]Me.Requery[/COLOR]
[COLOR=#1f497d]Me.Refresh[/COLOR]
[COLOR=#1f497d]Me.LastName = Null[/COLOR]
[COLOR=#1f497d]End Sub[/COLOR]
[/COLOR]
Code:
[COLOR=#1f497d][COLOR=#1f497d]Private Sub SaveNewMember_Click()[/COLOR]
[COLOR=#1f497d]DoCmd.RunCommand acCmdRefresh[/COLOR]
[COLOR=#1f497d]DoCmd.RunCommand acCmdSaveRecord[/COLOR]
[COLOR=#1f497d]Me.Requery[/COLOR]
[COLOR=#1f497d]Me.Refresh[/COLOR]
[COLOR=#1f497d]Me.LastName = Null[/COLOR]
[COLOR=#1f497d]End Sub[/COLOR]
[/COLOR]
Hope I got the duplicates out…I do realize some of the above examples are without the sub routine start and end statements, for clarification.
Some of the things I have tried come from several searches on this forum.