Error 2448 from 2nd level Subform

B

Blake D.

To head off the warnings:
Yes, I am aware of Access's "issues" with GUID's. Unfortunately, I
have need of using them. Changing to an autonumber integer is not a
valid solution in this scenario.

Form names and control names have been altered for simplicity.


Scenario:
Main_Form is an unbound form containing Main_Listbox.
Main_Listbox is unbound, with it's record source being a query pulling
data from tbl_Clients. It exposes the table's PK (an autonumber GUID).

First_Subform is an unbound subform containing First_Listbox. There is
no Master/Child relationship established.
First_Listbox is unbound, with it's record source being a query
pulling data from tbl_Life_Factors where Client_GUID =
[forms]![Main_Form].[Main_Listbox]. It exposes the table's PK
(RECORD_ID, also an autonumber GUID).
The tbl_Clients and tbl_Life_Factors are in a one-to-many with
tbl_Client's PK being an FK in tbl_Life_Factors.
Second_Subform is a bound subform inside First_Subform. There is a
Master (First_Listbox) / Child (RECORD_ID) relationship between the
two. It is a single-form form-view of all fields in the record.


Additions and Edits are turned off by default at all levels.


Problem:
Once a client record is selected on Main_Listbox, First_Listbox
populates automatically with all the associated life-factor records.
The first record is automatically selected and displayed on
Second_Subform. I am adding a button on the Main_Form that will allow
a user to add a new Life_Factors record. The subform opens to a blank
record, with the foreign key already carried over (the field on the
form has a default value of
"=Guidfromstring([Forms]![Main_Form]![Main_Listbox])") and the
RECORD_ID showing "(Autonumber)".

It works flawlessly. Except - When you first enter a value into in the
Second_Subform (doesn't matter what field), it throws an error 2448:
"You can't assign a value to this object." It is coming from the
(Autonumber) placeholder being replaced by an actual GUID as far as I
can tell.

Help Needed:
I either need to find out why it's objecting to the creation of the
record's autonumber, or I need to trap the error and shut it the hell
up. That's the kicker - once you click on the error, the record can be
SAVED! It works. It just fusses. =P


Code:
Main_Form
Add_Record_Button_Click()


Forms!Main_Form.First_Subform.Form.Second_Subform.Form.AddLifeFactor


Second_Subform
Public Sub AddLifeFactor()
On Error GoTo Error_Handler_AddLifeFactor


'Make Form Add-able
With Me
.Parent.Form.AllowAdditions = True
.Parent.Form.AllowEdits = True
.Form.AllowAdditions = True
.Form.AllowEdits = True
.Form.DataEntry = True
End With


'Set Focus to Life Factors Listbox, set it to no record selected
Me.Parent.Controls("First_Listbox").SetFocus
Me.Parent.Controls("First_Listbox").ListIndex = -1


'Give user visual feedback of change in editability of record
'Change background color of form detail area
Me.Detail.BackColor = 12624058
'Change background color of labels
Newcolor = 8212851
ToggleLabels (Newcolor)


'Disable Master Client list to prevent record changing during
addition
Me.Parent.Controls("Second_Subform").SetFocus
Me.Parent.Parent.Controls("Main_Listbox").Enabled = False


Me.Parent.Controls("First_Listbox").Enabled = False


Exit_AddLifeFactor:
Exit Sub


Error_Handler_AddLifeFactor:
MsgBox Err.Description
End Sub
 
B

Blake D.

For anyone who reads back this far, or who finds it via search:

I solved the problem by setting the subform.LinkChildField and
subform.LinkMasterField to a blank.


Once this was done, the record could be saved without error, and after
the save, you should be able to reassign the linking values
 

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