View Full Version : Using a submit button to enter data


Jonathan Abbott
05-07-2002, 06:03 AM
Here goes.

Thought I'd re-phrase the question.

Anyone help me with using a sumbit button to add data from a form and a sub form into relevant tables. I need to make sure all the info in the main form is present before being allowed to enter any data into the subform. I guess I need something to say If data in main form is correct then activate subform. Then i guess i need to write some code to submit the data from the main form and sub form into the tables where data is held.

any help would be appreciated as I'm going mad with this. As mentioned before I am new to Access.

Thanks

JA

[This message has been edited by Jonathan Abbott (edited 05-07-2002).]

chrismcbride
05-07-2002, 08:51 AM
I have not checked this but, I think the BeforeInsert event of the form fires before any navigation to sub form and before any data is copied to the bound table. You could perform you validation there and use the Cancel property of the event to stop saving of data based on your rules.
Alternatively you could use no bound controls on you form, put your validation behind the submit button and use a Sql Insert statement to add the data once validation is complete.
HTH
Chris

Jonathan Abbott
05-09-2002, 12:19 AM
Chris,

Thanks for this I think I am going to put my validation behind a submit button and then use a statement to add the data once validated. Next question is.......How do I do this? Can you give me an example. As I mentioned before I am very new to writing code and I cannot seem to find this in any of the books I have.

Thanks in advance.

JA http://www.access-programmers.co.uk/ubb/smile.gif

I have now managed to sort this out using the following code

Dim repname As String, Team As String, EMPno As String, Role As String, Mainproject As String, Mainprojectcode As String, month As String
repname = Forms!oncallinputform!repname.Value
Team = Forms!oncallinputform!Team.Value
EMPno = Forms!oncallinputform!EMPno.Value
Role = Forms!oncallinputform!Role.Value
Mainproject = Forms!oncallinputform!Mainproject.Value
Mainprojectcode = Forms!oncallinputform!Mainprojectcode.Value
month = Forms!oncallinputform!month.Value
Set Pers = CurrentDb.OpenRecordset("Personal_Details_Table", dbOpenDynaset)
Pers.AddNew
Pers![repname] = repname
Pers![Team] = Team
Pers![EMPno] = EMPno
Pers![Role] = Role
Pers![Mainproject] = Mainproject
Pers![Mainprojectcode] = Mainprojectcode
Pers![month] = month
Pers.Update
Pers.Close

Thanks!!!!

[This message has been edited by Jonathan Abbott (edited 05-10-2002).]