Changing allow edits impacts ability to add new record with subfor

L

LeLe

I have created an order entry form which contains a sub form for line item
entry. The properties for allow filters, edits, additions, deletions, are
all set to yes. When I first open the form, I am presented with the first
order placed in the application. When I click the arrow at the bottom of the
form for a new record, a blank order form complete with the sub form for line
item entry appears.

I want to change the form so when the user first opens the form, the allow
edits feature is set to No. I have created a button to do this and it works
fine. Here is the code.

Private Sub EditRecordBut_Click()
Me.AllowEdits = True 'Allow changes on the Order form
Forms![Orderentry]![LineItemOrderEntry].Form.AllowEdits = True ' Allow
changes on the line item subform
CustomerName.SetFocus 'Move the focus to the first field
End Sub

My problem is when I try to add a record. If I click on the arrow at the
bottom of the form, a new order form is created, but there is no line item
sub form. That area of the form is totally blank. Based on my observations,
I created the following code but it didn’t solve my problem. Any help is
greatly appreciated.

Private Sub AddRecLab_Click()
On Error GoTo Err_AddRecLab_Click

Me.AllowEdits = True
Forms![Orderentry]![LineItemOrderEntry].Form.AllowEdits = True
DoCmd.GoToRecord , , acNewRec
CustomerName.SetFocus

Exit_AddRecLab_Click:
Exit Sub

Err_AddRecLab_Click:
MsgBox Err.Description
Resume Exit_AddRecLab_Click

End Sub
 
D

Dale Fye

LeLe

How are the subform and the main form linked? Are you using the
Master/Child relationships, or some other method.

The challenge with working with subforms is that the record on the main form
must exist (have been saved) before you can populate any recods in the
subform (at least that is the case if your table structure has OrderID (or
something like it) as the PK in your Orders table, and as the FK in the
OrderDetails table. So until the PK for the new Order is written, you
cannot add details.

When I use this format, I generally have a "Add Order Details" button on the
main form. In the forms current event, I test to see whether I am on a new
record. If not, then I automatically display the details subform. If on a
new record, I actually hide the subform and set its SourceObject = "".
Then, when the user click the "Add Order Details" button, I save the current
record on the main form, and set the SourceObject to the appropriate Form
and make it visible.

HTH
Dale
 
L

LeLe

Thanks so much for your help. Everything you suggested makes sense; however,
here is the strange part: I open the application with an autoexec macro that
opens the order entry form in edit mode. The second action is GoToRecord and
the argument for Record = New. This works perfectly. Both the Order Header
and the sub form for line items appears without any data being saved and
accepts data no problem. This makes me believe that I can reveal the subform
even before the main form is saved. Why will it only work in response to the
autoexec macro. Thanks

Dale Fye said:
LeLe

How are the subform and the main form linked? Are you using the
Master/Child relationships, or some other method.

The challenge with working with subforms is that the record on the main form
must exist (have been saved) before you can populate any recods in the
subform (at least that is the case if your table structure has OrderID (or
something like it) as the PK in your Orders table, and as the FK in the
OrderDetails table. So until the PK for the new Order is written, you
cannot add details.

When I use this format, I generally have a "Add Order Details" button on the
main form. In the forms current event, I test to see whether I am on a new
record. If not, then I automatically display the details subform. If on a
new record, I actually hide the subform and set its SourceObject = "".
Then, when the user click the "Add Order Details" button, I save the current
record on the main form, and set the SourceObject to the appropriate Form
and make it visible.

HTH
Dale

LeLe said:
I have created an order entry form which contains a sub form for line item
entry. The properties for allow filters, edits, additions, deletions, are
all set to yes. When I first open the form, I am presented with the first
order placed in the application. When I click the arrow at the bottom of
the
form for a new record, a blank order form complete with the sub form for
line
item entry appears.

I want to change the form so when the user first opens the form, the allow
edits feature is set to No. I have created a button to do this and it
works
fine. Here is the code.

Private Sub EditRecordBut_Click()
Me.AllowEdits = True 'Allow changes on the Order form
Forms![Orderentry]![LineItemOrderEntry].Form.AllowEdits = True ' Allow
changes on the line item subform
CustomerName.SetFocus 'Move the focus to the first field
End Sub

My problem is when I try to add a record. If I click on the arrow at the
bottom of the form, a new order form is created, but there is no line item
sub form. That area of the form is totally blank. Based on my
observations,
I created the following code but it didn't solve my problem. Any help is
greatly appreciated.

Private Sub AddRecLab_Click()
On Error GoTo Err_AddRecLab_Click

Me.AllowEdits = True
Forms![Orderentry]![LineItemOrderEntry].Form.AllowEdits = True
DoCmd.GoToRecord , , acNewRec
CustomerName.SetFocus

Exit_AddRecLab_Click:
Exit Sub

Err_AddRecLab_Click:
MsgBox Err.Description
Resume Exit_AddRecLab_Click

End Sub
 
D

Dale Fye

Don't know, I don't use macros.

Try opening the form using the Open form method, from the immediate window,
and see what happens. You will want to use the acFormAdd to emulate the
Record = New in your macro, something like:

docmd.OpenForm "formname", acNormal, , , acFormAdd

What version of Access are you using?

Can you repost the code that is in the Main forms Open, Current and Load
events?

Dale

LeLe said:
Thanks so much for your help. Everything you suggested makes sense;
however,
here is the strange part: I open the application with an autoexec macro
that
opens the order entry form in edit mode. The second action is GoToRecord
and
the argument for Record = New. This works perfectly. Both the Order
Header
and the sub form for line items appears without any data being saved and
accepts data no problem. This makes me believe that I can reveal the
subform
even before the main form is saved. Why will it only work in response to
the
autoexec macro. Thanks

Dale Fye said:
LeLe

How are the subform and the main form linked? Are you using the
Master/Child relationships, or some other method.

The challenge with working with subforms is that the record on the main
form
must exist (have been saved) before you can populate any recods in the
subform (at least that is the case if your table structure has OrderID
(or
something like it) as the PK in your Orders table, and as the FK in the
OrderDetails table. So until the PK for the new Order is written, you
cannot add details.

When I use this format, I generally have a "Add Order Details" button on
the
main form. In the forms current event, I test to see whether I am on a
new
record. If not, then I automatically display the details subform. If on
a
new record, I actually hide the subform and set its SourceObject = "".
Then, when the user click the "Add Order Details" button, I save the
current
record on the main form, and set the SourceObject to the appropriate Form
and make it visible.

HTH
Dale

LeLe said:
I have created an order entry form which contains a sub form for line
item
entry. The properties for allow filters, edits, additions, deletions,
are
all set to yes. When I first open the form, I am presented with the
first
order placed in the application. When I click the arrow at the bottom
of
the
form for a new record, a blank order form complete with the sub form
for
line
item entry appears.

I want to change the form so when the user first opens the form, the
allow
edits feature is set to No. I have created a button to do this and it
works
fine. Here is the code.

Private Sub EditRecordBut_Click()
Me.AllowEdits = True 'Allow changes on the Order form
Forms![Orderentry]![LineItemOrderEntry].Form.AllowEdits = True ' Allow
changes on the line item subform
CustomerName.SetFocus 'Move the focus to the first field
End Sub

My problem is when I try to add a record. If I click on the arrow at
the
bottom of the form, a new order form is created, but there is no line
item
sub form. That area of the form is totally blank. Based on my
observations,
I created the following code but it didn't solve my problem. Any help
is
greatly appreciated.

Private Sub AddRecLab_Click()
On Error GoTo Err_AddRecLab_Click

Me.AllowEdits = True
Forms![Orderentry]![LineItemOrderEntry].Form.AllowEdits = True
DoCmd.GoToRecord , , acNewRec
CustomerName.SetFocus

Exit_AddRecLab_Click:
Exit Sub

Err_AddRecLab_Click:
MsgBox Err.Description
Resume Exit_AddRecLab_Click

End Sub
 

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