Copy all button

J

jamccarley

I currently have a button that copies all of the fields into the next record.
It was working, but now it is giving me a "Invalid use of null" error. What
code should I use to allow a null value to be copied? Here is the code I have
so far.

Private Sub Command573_Click()

ctrl4 = [Date Found]
ctrl5 = [PartNo]
ctrl6 = [Area]
ctrl7 = [Line]
ctrl8 = [Hold Area]
ctrl9 = [Process Identifier]
ctrl10 = [Initiated by]
ctrl11 = [Responsible Department]
ctrl12 = [Quality Engineers]
ctrl13 = [Supervisor Notified]
ctrl14 = [Problem]
ctrl15 = [How found]
ctrl16 = [Suspect Range]
ctrl17 = [Root Cause]
ctrl18 = [Comments]
DoCmd.GoToRecord , , acNewRec
[Date Found] = ctrl4
[PartNo] = ctrl5
[Area] = ctrl6
[Line] = ctrl7
[Hold Area] = ctrl8
[Process Identifier] = ctrl9
[Initiated by] = ctrl10
[Responsible Department] = ctrl11
[Quality Engineers] = ctrl12
[Supervisor Notified] = ctrl13
[Problem] = ctrl14
[How found] = ctrl15
[Suspect Range] = ctrl16
[Root Cause] = ctrl17
[Comments] = ctrl18

End Sub


Thank you
Josh
 
J

John Spencer

Do you know which line that fails on? Which line generates the error?

Have you declared the data types of ctrl4 to ctrl18?

Dim ctrl4 as Variant, ctrl5 as Variant, ...

If you did not declare them as variants but did declare them as strings,
dates, or a number type then if you try to set them to a null value you
will get the invalid use of null error.

You could test in each case
If Not IsNull([Date Found]) Then Ctrl4 = [Date Found]

The problem is that when you go to assign the values in the new record,
you will get the default value of the declared type. For a date you
will get Dec 30, 1899, for a number - 0, for a string - "".

Another possibility is that you must save the record before you copy the
values.

'This line will force any unsaved changes to be saved. If the record
cannot be saved you will get an error.
If Me.Dirty Then Me.Dirty = False

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

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