Carry Key field to New Record Form and Save New Record

J

John D

My Main Form [FA1_OrgMaster] has a Combo Box [FA1_OrgMaster.cboOrgs] in which
the user selects an organization. The 2 cbo columns are [OrgID] (the Bound
Field) and [OrgName] from the Table [TAaa_Orgs]. Several synchronized
subforms on tabs display diff info about that Org.

One subform is [FA1s6_Locations]. I have an "Add New Location" button
[btnAddNewLoc] on this subform that opens the Add New Location Form
[FC3_LocationsNew].

The Table [TAba_OrgAdd] has a 2 field Primary Key - [OrgID] and an
[AutoNumber] (AutoNumber allows multiple locations). I need to "copy" the
OrgID from [FA1_OrgMaster.cboOrgs] over into [FC3_LocationsNew]. Then when
the form is filled out (leaving aside other issues) I want to write the new
record to [TAba_OrgAdd]. I ASSUME the AutoNumber would be generated at that
time.

I've tried a bunch of things to move the OrgID over, and then to save the
new record - but so far no go. Here's the latest code:

Private Sub btnAddNewLoc_Click()

' Copy OrgID to a variable to paste into New Location Record
Dim NewLocOrgID As Integer
NewLocOrgID = Forms!FA1_OrgMaster_All.cboOrgs.Value

' Open New Location Form, enter OrgID
DoCmd.OpenForm "FC3_LocationNew"
Forms!FC3_LocationNew!OrgID = NewLocOrgID

End Sub

I get a "Field cannot be updated (Error 3164)" - with possible causes being
trying to update a field locked by another user. [FC3_LocationNew.OrgID] is
NOT locked. [FC3_LocationNew] properties include AllowEdits = No,
AllowDeletions = No, AllowAdditions = Yes, DataEntry = Yes. Recordset is
Dynaset with No Record Locks.

Awhile ago I was not getting this error on trying to open [FC3_LocationNew]
(I'm moving backwards!). But when I then filled out a new record on the form
and clicked my Save Button [btnSave] I got an error about "empty (or null
value in) Primary Key". The code behind that button is:

Private Sub btnSave_Click()

' Save record
If Me.Dirty Then Me.Dirty = False

DoCmd.Close acForm, "FC3_LocationNew", acSavePrompt

End Sub

Anyone see what I need to do? Or even what questions to ask? Thanks - John D
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top