JARICHARDUSA
asked on
clearing form except for certain fields
This is what I'm trying to do.
I have a form in which a user enters all information for a part in order to add this part into a database. If however the user has multiple numbers of the same part, instead of recreating everything from scratch, I want it so that the user just has to click a "save and duplicate" button in which case the data they just entered will be saved as a record in the database and then the form will requery but maintain the information incertain fields such as part name, NSN, ect. (basically the fields that will not change at all for that particular part) and the other fields will be empty for entering the new information such as Serial Number and such. The following is the code I currently have on that button:
Private Sub Command92_Click()
On Error GoTo Err_Command92_Click
DoCmd.RunCommand acCmdSaveRecord
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
Me.Base = ""
Me.Building = ""
Me.txtHRDate = ""
Me.txtComments = ""
Me.txtContactNumber = ""
Me.txtHRTo = ""
Me.txtHRDueDate = ""
Exit_Command92_Click:
Exit Sub
Err_Command92_Click:
MsgBox Err.Description
Resume Exit_Command92_Click
End Sub
This, however, is giving me an error: "object does not support this property or method"
The record is being saved to the database, though, its just giving me the above error and then not clearing out the fields I'd like cleared prior to creating a new record.
I have a form in which a user enters all information for a part in order to add this part into a database. If however the user has multiple numbers of the same part, instead of recreating everything from scratch, I want it so that the user just has to click a "save and duplicate" button in which case the data they just entered will be saved as a record in the database and then the form will requery but maintain the information incertain fields such as part name, NSN, ect. (basically the fields that will not change at all for that particular part) and the other fields will be empty for entering the new information such as Serial Number and such. The following is the code I currently have on that button:
Private Sub Command92_Click()
On Error GoTo Err_Command92_Click
DoCmd.RunCommand acCmdSaveRecord
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
Me.Base = ""
Me.Building = ""
Me.txtHRDate = ""
Me.txtComments = ""
Me.txtContactNumber = ""
Me.txtHRTo = ""
Me.txtHRDueDate = ""
Exit_Command92_Click:
Exit Sub
Err_Command92_Click:
MsgBox Err.Description
Resume Exit_Command92_Click
End Sub
This, however, is giving me an error: "object does not support this property or method"
The record is being saved to the database, though, its just giving me the above error and then not clearing out the fields I'd like cleared prior to creating a new record.
LOL
@Helen, Access 2003 command button wizards create this code for a Save Record button
I haven't tried the wizards in 2007 or 2010 yet...but I bet you they may STILL use the same code.
Anyway,
@JARICHARDUSA ,
Attack it the other way around.
You are presently saving, copying the whole record, and then trying to remove some stuff
Go at it the other way.
Save the values from the fields you want to keep into some variables.
Save the record and go to a new one
Write the values of your variables to the controls you'd like pre-loaded
As a bonus, if the user changes their mind, you can ESC or cancel the changes instead of having to delete the now-unwanted record
@Helen, Access 2003 command button wizards create this code for a Save Record button
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
So his code isn't necessarily old.I haven't tried the wizards in 2007 or 2010 yet...but I bet you they may STILL use the same code.
Anyway,
@JARICHARDUSA ,
Attack it the other way around.
You are presently saving, copying the whole record, and then trying to remove some stuff
Go at it the other way.
Save the values from the fields you want to keep into some variables.
Save the record and go to a new one
Write the values of your variables to the controls you'd like pre-loaded
As a bonus, if the user changes their mind, you can ESC or cancel the changes instead of having to delete the now-unwanted record
Dim mySomething as string
Dim MyOtherValue as string
Dim myNumber as long
mySomething = me.txtSomething 'save the value in the control for use in a second
MyOtherValue = me.txtOtherValue 'save the value in the control for use in a second
MyNumber = me.txtNumber 'save the value in the control for use in a second
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdRecordsGoToNew
me.txtSomething=mySomething 'copy your saved value back
me.txtOtherValue=MyOtherValue 'copy your saved value back
me.txtNumber=MyNumber 'copy your saved value back
ASKER
@Nick:
For each text box that I want to save the info then use over, I take it I make a Dim statement for each of those? For instance, say there were two text boxes txt_LIN and txt_NSN, I take it I would write it as:
Dim LIN as string
Dim NSN as string
LIN=me.txt_LIN
NSN=txt_NSN
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdRecordsGoToNew
me.txt_LIN=LIN me.txt_NSN=NSN
me.txtNumber=MyNumber
Now if the text field contains a number, which each of these does, do I have to usethe Dim MyNumber as long and use a number instead of a title in that phrase? for instance: Dim 1 as long then in the bottom part me.txt_LIN=1
I don't know a whole lot about the coding portion of access.
For each text box that I want to save the info then use over, I take it I make a Dim statement for each of those? For instance, say there were two text boxes txt_LIN and txt_NSN, I take it I would write it as:
Dim LIN as string
Dim NSN as string
LIN=me.txt_LIN
NSN=txt_NSN
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdRecordsGoToNew
me.txt_LIN=LIN me.txt_NSN=NSN
me.txtNumber=MyNumber
Now if the text field contains a number, which each of these does, do I have to usethe Dim MyNumber as long and use a number instead of a title in that phrase? for instance: Dim 1 as long then in the bottom part me.txt_LIN=1
I don't know a whole lot about the coding portion of access.
@Nick:
Access 2007 and 2010 "format" database wizards generate macros (Oy!)
The only way you can make the wizards generate Code is to leave the DB in the 2003 or older format...
:-)
Jeff
Access 2007 and 2010 "format" database wizards generate macros (Oy!)
The only way you can make the wizards generate Code is to leave the DB in the 2003 or older format...
:-)
Jeff
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
< your answer was precise, accurate and very short and simple>
How comes you did not award any points, then?
Please post your final code, and award points
How comes you did not award any points, then?
Please post your final code, and award points
ASKER
I did not intend to select my own comment, I meant to select Nicks response as the qualifying answer with the comments that I had written and awarded full points. Thank you.
ASKER
Thank You, same comments as before, I apologize for the accidentally awarding the points to myself.
No big deal, really.
But please, post your final, working code.
There might be some hairballs in it we could help you iron out!
But please, post your final, working code.
There might be some hairballs in it we could help you iron out!
Open in new window