Copy Record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I created a new command button on my form using the button wizard to allow me
to copy a record to a new record. When I click the button I get a Run-Time
error '94', Invalid use of Null. When I debug the error it highlights my code:

rs.FindFirst "[CertID] = " & Str(Me![cboSearchFilter])

On my form header I have a combo box that allows my user to select a
specific record to display on the form. Why would this interferre with the
copy command?
 
Is anything selected in the combo box? If not, that's the cause of your
Null. If so, what's the value of the bound column?
 
I created a new command button on my form using the button wizard to allow me
to copy a record to a new record. When I click the button I get a Run-Time
error '94', Invalid use of Null. When I debug the error it highlights my code:

rs.FindFirst "[CertID] = " & Str(Me![cboSearchFilter])

On my form header I have a combo box that allows my user to select a
specific record to display on the form. Why would this interferre with the
copy command?

Presumably the code is giving an error because it's being executed at
a time when cboSearchFilter is NULL. Are you certain that this is the
right control? From the name of the combo, it sounds like it might be
an unbound combo used to find a record - and you have no assurance
that the user has selected anything in it prior to clicking your
command button!

John W. Vinson [MVP]
 
No nothing is selected in the combo box. It's null until someone selects a
record from the pull down list. How do I correct this so I can use the copy
command even if the combo box is null?

Douglas J. Steele said:
Is anything selected in the combo box? If not, that's the cause of your
Null. If so, what's the value of the bound column?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
I created a new command button on my form using the button wizard to allow
me
to copy a record to a new record. When I click the button I get a Run-Time
error '94', Invalid use of Null. When I debug the error it highlights my
code:

rs.FindFirst "[CertID] = " & Str(Me![cboSearchFilter])

On my form header I have a combo box that allows my user to select a
specific record to display on the form. Why would this interferre with the
copy command?
 
No nothing is selected in the combo box. It's null until someone selects a
record from the pull down list. How do I correct this so I can use the copy
command even if the combo box is null?

eh???

"I haven't selected anything. Please copy it to a new record."

What is it that you want copied? How can Access tell?

John W. Vinson [MVP]
 
John,
The record selector that is on the form's header is only there so users can
select a record to modify the data. When the user first opens the form to
create a new record they won't be using the record selector so it's null.
Once they create a new record they might want to copy that record to another
new record. Again, the record selector won't have any value in it. That's
where the problem is.
 
John,
The record selector that is on the form's header is only there so users can
select a record to modify the data. When the user first opens the form to
create a new record they won't be using the record selector so it's null.
Once they create a new record they might want to copy that record to another
new record. Again, the record selector won't have any value in it. That's
where the problem is.

In that case, rather than using the record selector to specify which
record to copy, use a control (which could be invisible, if you wish)
which is bound to the ID field in the form.

You're getting what you are ASKING for... not what you want...

John W. Vinson [MVP]
 
I guess I'm not explaining myself correctly here.
Records that are already in the table will not be selected from the record
selector to have a copy made. Only when a user creates a new record. Once
they are done creating the new record is when they will need to copy it to
another new record. So that means that they will not be selecting a record
using the record selector which also means the record selector will have no
value in it at this point.The only time they will need to copy a record is
right after they create one. Other than that the copy function won't be used.
So how do I fix this from erroring out when a null value is in my record
selector?
 
.The only time they will need to copy a record is
right after they create one. Other than that the copy function won't be used.
So how do I fix this from erroring out when a null value is in my record
selector?

By using a control bound to the Primary Key of the newly created
record, which you should save to disk first, using a line like

DoCmd.RunCommand acCmdSaveRecord

rather than the record selector to specify the record to be copied.

I don't know what that control might be, since I cannot see your form
- but surely your table has a primary key field? Can you not just put
a textbox (maybe invisible) on the form, bound to that field, and use
THAT controlname instead of the record selector?

John W. Vinson [MVP]
 
Back
Top