Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2005, 03:57 AM
Registered User
 
Join Date: Apr 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jonwitts
Default Forms not saving information

Hi, I have been building a database for some time now, and felt I had got to point when I could start entering data into it to start building the reports and queries, however when I try and input sample data I run into problems.

The first form inputs correctly and saves and opens the next form, however on all subsequent forms the data is not saved.

Here is the VBA I use for the Save button on the first form...

Private Sub SaveRecord_Click()

Dim NextForm As String

    If Me.Status = "Pupil / Child" Then
        NextForm = "StudentDetail"
    Else
        NextForm = "EmployerDetails"
    End If

    DoCmd.save
    DoCmd.Close
    DoCmd.OpenForm NextForm
End Sub


Private Sub SaveRecord_DblClick(Cancel As Integer)

Dim NextForm As String

    If Me.Status = "Pupil / Child" Then
        NextForm = "StudentDetail"
    Else
        NextForm = "EmployerDetails"
    End If

    DoCmd.save
    DoCmd.Close
    DoCmd.OpenForm NextForm

End Sub


And here is the code I am using for the Save button on form "EmployerDetails"

Private Sub SaveRecord_Click()

DoCmd.save
DoCmd.Close
DoCmd.OpenForm "GeneralInfo"

End Sub


Private Sub SaveRecord_DblClick(Cancel As Integer)

DoCmd.save
DoCmd.Close
DoCmd.OpenForm "GeneralInfo"

End Sub


I can not work out why this would not save the data into the table "EmployerDetails" and why Access is not prompting me of the errors. Please help.
 
Old August 1st, 2005, 05:16 AM
Registered User
 
Join Date: Apr 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jonwitts
Default

I have been looking further into this, and have added a "Save record" Control box, by using the wizard which gives me this code,

Private Sub Command23_Click()
On Error GoTo Err_Command23_Click


    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Command23_Click:
    Exit Sub

Err_Command23_Click:
    MsgBox Err.Description
    Resume Exit_Command23_Click

End Sub

Now when I navigate to "Employer Details" after filling out "PersonDetails" then click on "Command23" button, I get the error window "You can not add or change a record because a related record is required in table "PersonDetails".

Well the related record is present in "PersonDEtails" as I can view the data entered in the table view, however the link between "PersonDetails.PersonKey" and "EmployerDetails.PersonKey" does not appear to work...

What could I have done wrong that would cause the form not to get the PersonKey field from the previous table???

Surely there is a way where the user would not have to input the PersonKey on every form they are entering??
 
Old August 1st, 2005, 09:14 AM
Authorized User
 
Join Date: Jun 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You definitely do NOT want the user to enter the PersonKey on any form. What you do want to do is fill the value of the employer form with PersonKey using VBA prior to the save.

One way to do this is have a textbox in the employer form called me.PersonKey(which probably should be invisible), linked to Employer.Personkey.

Then, have the assignment before the save:

Me.PersonKey=<<some value>>.
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70


<<some value>> would be, of course, the Personkey from PersonDetails. There are many ways to pass this value to the current screen. But it has to be done explicitly, unless you are using a linked subform, which is another topic.

The other thing here is that your data model seems like it could use some improvement, if i understand correctly how you seem to have things set up. That's also another topic.

I hope this is somewhat helpful to you.










Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows forms saving siva211662 C# 3 November 21st, 2008 01:14 PM
Saving Themes Information in SQL 2000 sudhakar_d191080 ASP.NET 2.0 Professional 0 June 8th, 2007 06:54 AM
saving table of information back into database mrjits Excel VBA 3 July 17th, 2006 01:42 PM
Saving forms rgerald Access 3 April 5th, 2006 11:55 AM
Saving forms in drag and Drop rylemer Javascript 0 February 26th, 2004 01:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.