Hello all,
I am pretty much a beginner in Access, although I did create a few basic databases with access 97 a long time back !
I am trying to create a database to manage IT assets, most of the structure is done, I'm now trying to get the details done.
The issue I am currently trying to tackle is to get a control button on one form to create a new record in the sub form that sits in the main form via another pop-up form.
So I have :
>PeripheralsViewForm - that has 4 control buttons (Edit Quantity, Edit Description,Add an Item and Exit)
>> PeripheralsSubForm - (Datasheet) which is referenced to PeripheralsQuery
The Edit Quantity and Edit Description open a separate form which allows the user to update only the quantity or description respectively (I have done it this way rather than allowing edits in the data sheet as I feel that it is too easy to hit a key incorrectly and overwrite data in the datasheet view)
Both of these functions work perfectly (to my amazement) - I am using the id field in the subform to link to the pop-up form which then has unbound text input boxes, which I then write back to the subform.
e.g from edit button on click event: DoCmd.OpenForm "perquantform", , , " ID=" & Form.PeripheralsSubForm!ID
and then from the pop-up form "perquantform" on the "Exit & Save" button I have : Forms!peripheralsViewForm.PeripheralsSubForm.Form!Quantity = Me.newquant
DoCmd.Close acForm, "perquantform", acSaveYes
This allows the user to select the record in the datasheet form and then click either the change quantity or description button.
I watched a tutorial that did the same thing by putting a edit button next to each record, but that looked naff to me !
Also also the other reason I did it this way was because I just couldn't get the subform to requery when I had the two edit popups linked to the table or query.
The problem now is that when I click on the "Add an Item" button, it overwrites whatever record is currently selected !!
The code I have is this:
From the "Add an Item" button on click action:
DoCmd.GoToRecord , Forms!peripheralsViewForm!PeripheralsSubForm.Form!, acNewRec
DoCmd.OpenForm "addperform"
And from the form "addperform" - "Save & Exit" button on click action:
Forms!peripheralsViewForm.PeripheralsSubForm.Form!PerType = Me.pertypedrop
Forms!peripheralsViewForm.PeripheralsSubForm.Form!PerMake = Me.permakedrop
Forms!peripheralsViewForm.PeripheralsSubForm.Form!PerModel = Me.newmodel
Forms!peripheralsViewForm.PeripheralsSubForm.Form!PerDescription = Me.newdescription
Forms!peripheralsViewForm.PeripheralsSubForm.Form!Quantity = Me.newquantity
DoCmd.OpenForm "PeripheralsViewForm"
DoCmd.Close acForm, "addperform"
--------------------------------------
the line "DoCmd.GoToRecord , Forms!peripheralsViewForm!PeripheralsSubForm.Form!, acNewRec" is what I have added to try to solve the overwrite issue, but when I run this it comes up with the error :
"runtime error 2498 - An expression you entered is the wrong data type for one of the arguments"
I have put this line in the "addperform" exit action and it comes up with the same sort of error.
Please could one of you experty types tell me what I am doing wrong (other than attempting to write a database with very little knowledge !)
And yes I know that my naming conventions are rubbish !, once I really know what I am doing I will probably rewrite the whole thing, but for now I just need it to work as I can't manage the department that I have taken on with multiple unlinked and non standardized Excel spreadsheets :banghead:
So if anyone can help me I would be eternally grateful !
Kind regards to all
Damian
Sorry should of said . . Using Access 2010
I am pretty much a beginner in Access, although I did create a few basic databases with access 97 a long time back !
I am trying to create a database to manage IT assets, most of the structure is done, I'm now trying to get the details done.
The issue I am currently trying to tackle is to get a control button on one form to create a new record in the sub form that sits in the main form via another pop-up form.
So I have :
>PeripheralsViewForm - that has 4 control buttons (Edit Quantity, Edit Description,Add an Item and Exit)
>> PeripheralsSubForm - (Datasheet) which is referenced to PeripheralsQuery
The Edit Quantity and Edit Description open a separate form which allows the user to update only the quantity or description respectively (I have done it this way rather than allowing edits in the data sheet as I feel that it is too easy to hit a key incorrectly and overwrite data in the datasheet view)
Both of these functions work perfectly (to my amazement) - I am using the id field in the subform to link to the pop-up form which then has unbound text input boxes, which I then write back to the subform.
e.g from edit button on click event: DoCmd.OpenForm "perquantform", , , " ID=" & Form.PeripheralsSubForm!ID
and then from the pop-up form "perquantform" on the "Exit & Save" button I have : Forms!peripheralsViewForm.PeripheralsSubForm.Form!Quantity = Me.newquant
DoCmd.Close acForm, "perquantform", acSaveYes
This allows the user to select the record in the datasheet form and then click either the change quantity or description button.
I watched a tutorial that did the same thing by putting a edit button next to each record, but that looked naff to me !
Also also the other reason I did it this way was because I just couldn't get the subform to requery when I had the two edit popups linked to the table or query.
The problem now is that when I click on the "Add an Item" button, it overwrites whatever record is currently selected !!
The code I have is this:
From the "Add an Item" button on click action:
DoCmd.GoToRecord , Forms!peripheralsViewForm!PeripheralsSubForm.Form!, acNewRec
DoCmd.OpenForm "addperform"
And from the form "addperform" - "Save & Exit" button on click action:
Forms!peripheralsViewForm.PeripheralsSubForm.Form!PerType = Me.pertypedrop
Forms!peripheralsViewForm.PeripheralsSubForm.Form!PerMake = Me.permakedrop
Forms!peripheralsViewForm.PeripheralsSubForm.Form!PerModel = Me.newmodel
Forms!peripheralsViewForm.PeripheralsSubForm.Form!PerDescription = Me.newdescription
Forms!peripheralsViewForm.PeripheralsSubForm.Form!Quantity = Me.newquantity
DoCmd.OpenForm "PeripheralsViewForm"
DoCmd.Close acForm, "addperform"
--------------------------------------
the line "DoCmd.GoToRecord , Forms!peripheralsViewForm!PeripheralsSubForm.Form!, acNewRec" is what I have added to try to solve the overwrite issue, but when I run this it comes up with the error :
"runtime error 2498 - An expression you entered is the wrong data type for one of the arguments"
I have put this line in the "addperform" exit action and it comes up with the same sort of error.
Please could one of you experty types tell me what I am doing wrong (other than attempting to write a database with very little knowledge !)
And yes I know that my naming conventions are rubbish !, once I really know what I am doing I will probably rewrite the whole thing, but for now I just need it to work as I can't manage the department that I have taken on with multiple unlinked and non standardized Excel spreadsheets :banghead:
So if anyone can help me I would be eternally grateful !
Kind regards to all
Damian
Sorry should of said . . Using Access 2010
Last edited: