Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Null Value


Message #1 by "Lesley Schulz" <lesley.schulz@h...> on Fri, 24 May 2002 02:39:14
I have a form where they can edit parts and also add new parts.  I get an 
error message Index or primary key can't contain a null value & can't move 
to a specified recordset. 

I have a combo box where they can select the part they want to edit and I 
have an "Add Record" button to add a new record.  But if you select 
the "AddRecord" button but don't add anything and select a part from the 
combo box to go to, then I get the error messages above.  

Are there any solutions for this error?

Here is the code for the combo box:
Sub Combo39_AfterUpdate()
    ' Find the record that matches the control.
    Me.RecordsetClone.FindFirst "[Procurement_PN] = '" & Me![Combo39] & "'"
    Me.Bookmark = Me.RecordsetClone.Bookmark
            
End Sub

Here is the code for the "Add Record" button:
Private Sub cmdAddRecord_Click()
On Error GoTo Err_cmdAddRecord_Click

    DoCmd.GoToRecord , , acNewRec
    'Procurement_PN.SetFocus
     Me.Refresh
     Entry_Date = Now()
          
Exit_cmdAddRecord_Click:
    Exit Sub

Err_cmdAddRecord_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddRecord_Click

Thanks
Lesley
Message #2 by "Wesley Kendrick" <wez.k@n...> on Fri, 24 May 2002 16:40:14 +0100
what is the primary key field in your underlying table set to? it should be
'autonumber'.
regards, Wesley Kendrick

----- Original Message -----
From: "Lesley Schulz" <lesley.schulz@h...>
To: "Access" <access@p...>
Sent: Friday, May 24, 2002 2:39 AM
Subject: [access] Null Value


> I have a form where they can edit parts and also add new parts.  I get an
> error message Index or primary key can't contain a null value & can't move
> to a specified recordset.
>
> I have a combo box where they can select the part they want to edit and I
> have an "Add Record" button to add a new record.  But if you select
> the "AddRecord" button but don't add anything and select a part from the
> combo box to go to, then I get the error messages above.
>
> Are there any solutions for this error?
>
> Here is the code for the combo box:
> Sub Combo39_AfterUpdate()
>     ' Find the record that matches the control.
>     Me.RecordsetClone.FindFirst "[Procurement_PN] = '" & Me![Combo39] &
"'"
>     Me.Bookmark = Me.RecordsetClone.Bookmark
>
> End Sub
>
> Here is the code for the "Add Record" button:
> Private Sub cmdAddRecord_Click()
> On Error GoTo Err_cmdAddRecord_Click
>
>     DoCmd.GoToRecord , , acNewRec
>     'Procurement_PN.SetFocus
>      Me.Refresh
>      Entry_Date = Now()
>
> Exit_cmdAddRecord_Click:
>     Exit Sub
>
> Err_cmdAddRecord_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdAddRecord_Click
>
> Thanks
> Lesley
>

Message #3 by "Lesley Schulz" <lesley.schulz@h...> on Fri, 24 May 2002 19:10:45
> what is the primary key field in your underlying table set to? it should 
be
'autonumber'.
regards, Wesley Kendrick

----- Original Message -----
From: "Lesley Schulz" <lesley.schulz@h...>
To: "Access" <access@p...>
Sent: Friday, May 24, 2002 2:39 AM
Subject: [access] Null Value


> I have a form where they can edit parts and also add new parts.  I get an
> error message Index or primary key can't contain a null value & can't 
move
> to a specified recordset.
>
> I have a combo box where they can select the part they want to edit and I
> have an "Add Record" button to add a new record.  But if you select
> the "AddRecord" button but don't add anything and select a part from the
> combo box to go to, then I get the error messages above.
>
> Are there any solutions for this error?
>
> Here is the code for the combo box:
> Sub Combo39_AfterUpdate()
>     ' Find the record that matches the control.
>     Me.RecordsetClone.FindFirst "[Procurement_PN] = '" & Me![Combo39] &
"'"
>     Me.Bookmark = Me.RecordsetClone.Bookmark
>
> End Sub
>
> Here is the code for the "Add Record" button:
> Private Sub cmdAddRecord_Click()
> On Error GoTo Err_cmdAddRecord_Click
>
>     DoCmd.GoToRecord , , acNewRec
>     'Procurement_PN.SetFocus
>      Me.Refresh
>      Entry_Date = Now()
>
> Exit_cmdAddRecord_Click:
>     Exit Sub
>
> Err_cmdAddRecord_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdAddRecord_Click
>
> Thanks
> Lesley
>

My Primary Key is set to Procurement_PN

If I add an autoNumber column, does it automatically populate the column?

Thanks
Lesley
Message #4 by "Gerald, Rand" <RGerald@u...> on Fri, 24 May 2002 13:13:24 -0500
You could try not updating the recordset unless there was an actual 
value in
the combo box.

For example, building on your code:

Sub Combo39_AfterUpdate()
	If Not IsNull(Me![Combo39]) Then
     ' Find the record that matches the control.
     Me.RecordsetClone.FindFirst "[Procurement_PN] =3D '" & 
Me![Combo39] & "'"
     Me.Bookmark =3D Me.RecordsetClone.Bookmark
	End If
End Sub


Rand E Gerald
Database Specialist
Information Services / Operations
Bah=E1'=ED National Office
1233 Central St.
Evanston IL 60201
(xxx) xxx-xxxx

-----Original Message-----
From: Lesley Schulz [mailto:lesley.schulz@h...]
Sent: Friday, May 24, 2002 2:11 PM
To: Access
Subject: [access] Re: Null Value

> what is the primary key field in your underlying table set to? it 
should
be
'autonumber'.
regards, Wesley Kendrick

----- Original Message -----
From: "Lesley Schulz" <lesley.schulz@h...>
To: "Access" <access@p...>
Sent: Friday, May 24, 2002 2:39 AM
Subject: [access] Null Value


> I have a form where they can edit parts and also add new parts.  I 
get an
> error message Index or primary key can't contain a null value & can't
move
> to a specified recordset.
>
> I have a combo box where they can select the part they want to edit 
and I
> have an "Add Record" button to add a new record.  But if you select
> the "AddRecord" button but don't add anything and select a part from 
the
> combo box to go to, then I get the error messages above.
>
> Are there any solutions for this error?
>
> Here is the code for the combo box:
> Sub Combo39_AfterUpdate()
>     ' Find the record that matches the control.
>     Me.RecordsetClone.FindFirst "[Procurement_PN] =3D '" & 
Me![Combo39] &
"'"
>     Me.Bookmark =3D Me.RecordsetClone.Bookmark
>
> End Sub
>
> Here is the code for the "Add Record" button:
> Private Sub cmdAddRecord_Click()
> On Error GoTo Err_cmdAddRecord_Click
>
>     DoCmd.GoToRecord , , acNewRec
>     'Procurement_PN.SetFocus
>      Me.Refresh
>      Entry_Date =3D Now()
>
> Exit_cmdAddRecord_Click:
>     Exit Sub
>
> Err_cmdAddRecord_Click:
>     MsgBox Err.Description
>     Resume Exit_cmdAddRecord_Click
>
> Thanks
> Lesley
>

My Primary Key is set to Procurement_PN

If I add an autoNumber column, does it automatically populate the 
column?

Thanks
Lesley
Message #5 by "Wesley Kendrick" <wez.k@n...> on Fri, 24 May 2002 21:51:25 +0100
Yes it populates automatically.  Try adding this field and setting it as the
primary key.  I think your problem is that your present primary key is not
receiving a value immediateley the record is created. Therefore when the
program tries to move to that record, you get the error.  Hope that helps,
regards, Wesley

----- Original Message -----
From: "Lesley Schulz" <lesley.schulz@h...>
To: "Access" <access@p...>
Sent: Friday, May 24, 2002 7:10 PM
Subject: [access] Re: Null Value


> > what is the primary key field in your underlying table set to? it should
> be
> 'autonumber'.
> regards, Wesley Kendrick
>
> ----- Original Message -----
> From: "Lesley Schulz" <lesley.schulz@h...>
> To: "Access" <access@p...>
> Sent: Friday, May 24, 2002 2:39 AM
> Subject: [access] Null Value
>
>
> > I have a form where they can edit parts and also add new parts.  I get
an
> > error message Index or primary key can't contain a null value & can't
> move
> > to a specified recordset.
> >
> > I have a combo box where they can select the part they want to edit and
I
> > have an "Add Record" button to add a new record.  But if you select
> > the "AddRecord" button but don't add anything and select a part from the
> > combo box to go to, then I get the error messages above.
> >
> > Are there any solutions for this error?
> >
> > Here is the code for the combo box:
> > Sub Combo39_AfterUpdate()
> >     ' Find the record that matches the control.
> >     Me.RecordsetClone.FindFirst "[Procurement_PN] = '" & Me![Combo39] &
> "'"
> >     Me.Bookmark = Me.RecordsetClone.Bookmark
> >
> > End Sub
> >
> > Here is the code for the "Add Record" button:
> > Private Sub cmdAddRecord_Click()
> > On Error GoTo Err_cmdAddRecord_Click
> >
> >     DoCmd.GoToRecord , , acNewRec
> >     'Procurement_PN.SetFocus
> >      Me.Refresh
> >      Entry_Date = Now()
> >
> > Exit_cmdAddRecord_Click:
> >     Exit Sub
> >
> > Err_cmdAddRecord_Click:
> >     MsgBox Err.Description
> >     Resume Exit_cmdAddRecord_Click
> >
> > Thanks
> > Lesley
> >
>
> My Primary Key is set to Procurement_PN
>
> If I add an autoNumber column, does it automatically populate the column?
>
> Thanks
> Lesley
>

Message #6 by "Amy Wyatt" <amyw@c...> on Tue, 28 May 2002 22:15:29
I would hide the combo box when they invoke the Add Record. The problem 
you are encountering is because as soon as you add the date (now()) you 
have initiated a new record. Changing you primary Key to an auto number 
will solve this particular error but what will happen is you will get all 
sorts of orphan records with no PN number becuase it will ignore it, or, 
if this is sent to a unique value (PN) then you will only be able to do 
this once and then you will have the same problem.

You can either not put the date in at the press of Add New Record and wait 
until the fill in the PN before the date is put in or you need to have a 
cancel for the form to remove the record before it goes looking for a 
different record to edit.

Make your user choose between Adding a record and Editing a record.

Amy

> I have a form where they can edit parts and also add new parts.  I get 
an 
e> rror message Index or primary key can't contain a null value & can't 
move 
t> o a specified recordset. 

> I have a combo box where they can select the part they want to edit and 
I 
h> ave an "Add Record" button to add a new record.  But if you select 
t> he "AddRecord" button but don't add anything and select a part from the 
c> ombo box to go to, then I get the error messages above.  

> Are there any solutions for this error?

> Here is the code for the combo box:
S> ub Combo39_AfterUpdate()
 >    ' Find the record that matches the control.
 >    Me.RecordsetClone.FindFirst "[Procurement_PN] = '" & Me![Combo39] 
& "'"
 >    Me.Bookmark = Me.RecordsetClone.Bookmark
 >            
E> nd Sub

> Here is the code for the "Add Record" button:
P> rivate Sub cmdAddRecord_Click()
O> n Error GoTo Err_cmdAddRecord_Click

>     DoCmd.GoToRecord , , acNewRec
 >    'Procurement_PN.SetFocus
 >     Me.Refresh
 >     Entry_Date = Now()
 >          
E> xit_cmdAddRecord_Click:
 >    Exit Sub

> Err_cmdAddRecord_Click:
 >    MsgBox Err.Description
 >    Resume Exit_cmdAddRecord_Click

> Thanks
L> esley

  Return to Index