Error message when form opened in Edit Mode

G

Greg

I have a main form that I would like to open in Edit mode every time. I
changed Data Entry property to yes and it is working fine. On this form I
have few control buttons ( Exit, Find…) and subform. Form is based on table
with primary key defined. If I open a blank form in edit mode and click any
of control buttons or I highlight specific record from a subform I am
receiving error message “ index or primary key should not contain null
valueâ€. is there any other way to avoid this message without removing primary
key?
Thanks for your help
 
J

John W. Vinson

I have a main form that I would like to open in Edit mode every time. I
changed Data Entry property to yes and it is working fine.

Data Entry view lets you ONLY add new records; it conceals existing records,
so it cannot be used to edit. By default, forms *do* open in edit mode; it's
not necessary to change any properties to get them to do so!
On this form I
have few control buttons ( Exit, Find…) and subform. Form is based on table
with primary key defined. If I open a blank form in edit mode and click any
of control buttons or I highlight specific record from a subform I am
receiving error message “ index or primary key should not contain null
value”.

The mainform record is saved to disk the moment you set focus to any control
in the subform. This is necessary if (as is typical) the mainform is based on
the "One" side of a one to many relationship with the subform's table; you
can't add a record to the subform's table unless there is a corresponding
record in the main form to serve as the parent record.

Why do you feel that you need to enter a child record before adding the
parent?

I don't know what your buttons do but they may also be trying to save a
record. The error is saying exactly why you can't: every record in a table
must have a value in its Primary Key, and your form isn't providing such a
value! What IS the primary key of the table, and how are you intending that it
be set?
is there any other way to avoid this message without removing primary
key?

Adding a value for the primary key, either by typing it, by writing code to
fill it, or by changing its datatype to Autonumber.

John W. Vinson [MVP]
 
G

Greg

When main form is loaded first record from the table is displayed in main
form. I would like to start with blank main form and from blank main form I
would like to search for specific record. I am not trying to save record but
when I click Find record control button I am receiving error message: “index
or primary key should not contain null valueâ€

Private Sub FindTic_Click()
On Error GoTo Err_FindTic_Click


Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_FindTic_Click:
Exit Sub

Err_FindTic_Click:
MsgBox Err.Description
Resume Exit_FindTic_Click

End Sub
 
J

John W. Vinson

When main form is loaded first record from the table is displayed in main
form. I would like to start with blank main form and from blank main form I
would like to search for specific record. I am not trying to save record but
when I click Find record control button I am receiving error message: “index
or primary key should not contain null value”

Change the form's Data Entry property back to No. You can't find records in an
empty recordset, and that's precisely what Data Entry gives you.

Instead, use code in the form's Load event:

Private Sub Form_Load()
DoCmd.GoToRecord acDataForm, Me.Name, acNewRecord
End Sub

Are you using the builtin find-record command, or do you have a programmed
button on the form?

John W. Vinson [MVP]
 
G

Greg

Ok I change Data Entry property back to No, used code in form's Load event
and now I am getting Run Time error '2105' You can't go to the specified
record.
I am using builtin find-record command
 
J

John W. Vinson

Ok I change Data Entry property back to No, used code in form's Load event
and now I am getting Run Time error '2105' You can't go to the specified
record.

Please post your code.

Did you actually *try* the code I suggested?

John W. Vinson [MVP]
 

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