Form not opening to new record

G

Guest

Hi

I have the following code behind a command button which should open a second
form to a new record:

DoCmd.OpenForm "testfrm_PAI_2", , , , acFormAdd, , "Add"

The form is opening to a new record, but I cannot enter anything into any of
the text boxes. All controls are locked and unenabled in "View" or "Edit"
mode (other buttons on the switchboard, which are working fine), but I have
programmed the controls to be unlocked and enabled when in "Add" mode. When
the form is open, and on viewing the properties of the controls, they are
indeed unlocked and enabled, yet I cannot type anything in?

The following code is in the Form Open Event of testfrm_PAI_2:

Select Case Me.OpenArgs
Case "View"
'In "View" mode, Save/Cancel buttons invisible, Controls disabled
Call SaveCancelButtons_Off
Call Controls_Off

Case "Edit"
'In "Edit" mode, Exit/Edit buttons invisible, Controls enabled
Me.cmd_ExitForm.Visible = False
Me.lbl_ExitForm.Visible = False
Me.cmd_EditCert.Visible = False
Me.lbl_EditCert.Visible = False
Call Controls_On

Case "Add"
'In "Add" mode, Controls enabled, Exit/Edit/Del buttons disabled.
Call Controls_On
Me.cmd_ExitForm.Visible = False
Me.lbl_ExitForm.Visible = False
Me.cmd_EditCert.Visible = False
Me.lbl_EditCert.Visible = False
Me.cmd_DelCert.Visible = False
Me.lbl_DelCert.Visible = False
Me.cmd_CursorStop.SetFocus
Me.PAPOLICY_IDX.Enabled = True
Me.PAPOLICY_IDX.Locked = False
Me.PAPOLICY_IDX.SetFocus

Case Else
'Error message to go here

End Select

The procedures "Controls_On/Off" are basically only setting the Enabled and
Locked properties of various controls to True or False, depending on the
situation.

Is there something that I'm overlooking here that is causing the acFormAdd
to not let me enter anything in the controls?

Many thanks in anticipation of your help.
 
T

TC

I thiunk you're doing this the hard way! Check out the AllowAdditions,
AllowEdits and AllowDeletions properties of the form.

HTH,
TC [MVP Access]
 
G

Guest

Hi,

I know all about those, but I can't seem to control them through a button on
a different form.

If I don't specify the acFormAdd, then the form opens to whatever record was
open last through the "View" or "Edit" buttons.
 
T

TC

Set the three Allow* properties of the form, to True. Then control what
the form can do, by passing the appropriate selection parameter (eg.
acEdit) on the OpenForm call. You don't need any code, apart from the
OpenForm calls.

HTH,
TC [MVP Access]
 
G

Guest

Hi

Thanks for your suggestion. I have tried this before, but it doesn't "grey
out" the controls to indicate that they aren't editable. I can control this
through turning the enable property on and off, but I can't make it work when
I fiddle with the Allow properties.

Thanks anyway.
 
G

Guest

I figured out what was wrong with my code.

In the "Edit" and "View" codes I had an incorrect link criteria reference,
which sort of stuffed everything up. I had entered in "Me.Control" instead
of "Forms!FormName!Control". Once I fixed this, everything worked.
 

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