Problems when duplicating a record

N

night_writer

My apologies for posting this again, but I think first post was tacked
on to a thread that was too old.

I am running into problems doing anything to a record in a form after
I've duplicated it.
Here is my code:
~~~~
'variable applies at modular level
blnDuplicate = True 'I DON'T RUN AN ONCURRENT EVENT SUBROUTINE
IF
TRUE

Me.ProjectID.Enabled = True 'I NEED TO ENABLE THIS FIELD,
OTHERWISE IT DOESN'T SEEM TO COPY

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend

Me.strCircularNumber.SetFocus ' THIS IS WHERE IT BOMBS (SEE
BELOW)

blnDuplicate = False
~~~~

I need to move to strCircularNumber field, and then set
ProjectID.Enable to False and a few other things. The error I'm
getting is: "MS Office Access can't move the control to
strCircularNumber."

I've tried all sorts of things, and it appears that even though my
screen changes and appears to make the newly duplicated record the
current record, I just can't do anything with it! Other error messages
I've gotten trying various things make me think the record is not
being perceived as activated, even though it is current.

I am thinking there must be something very simple that I'm missing. I
just want to get control of this form again after I've appended the
record and I haven't been able to figure out how to do it!

Any help or advice would be greately appreciated.

Alice
 
R

roger

1. are you sure you have a *control* named "strCircularNumber" on the form?
2. is it visible?
3. are you sure the right form has the focus?

you might need a "doEvents" after the paste so that other after insert
events can fire.

If it were up to me, I'd dupe a record with an append query, or in VB I'd
just store a bunch of values in memory, goto New, and set values. (I wouldn't
use the clipboard.)

hth
roger
 
N

night_writer

1. are you sure you have a *control* named "strCircularNumber" on the form?
2. is it visible?
3. are you sure the right form has the focus?

you might need a "doEvents" after the paste so that other after insert
events can fire.

If it were up to me, I'd dupe a record with an append query, or in VB I'd
just store a bunch of values in memory, goto New, and set values. (I wouldn't
use the clipboard.)

hth
roger















- Show quoted text -

Thanks for the suggestions. I definately have a control named
strCircularNumber in my form, and it is definately visible. I think
the form has the focus, since its title bar is highlighted, but just
to make sure, I added "Me.SetFocus" after my "DoCmd" instructions.
"DoEvents" doesn't seem to make a difference, but I got a very
unexpected result when I tried to do this another way with:

DoCmd.GoToControl Me.strCircularNumber

I got an error message that access couldn't find a control named "LI-
CF-2007-175", which happens to be the contents of my control named
strCircularNumber.

I also tried: DoCmd.GoToControl Me.Controls([strCircularNumber]) but
I got the same result. There is nothing in my code setting
strCircularNumber to a variable. This is driving me crazy. I would
greatly apprecaite any additional suggestions!

Alice
 
N

night_writer

1. are you sure you have a *control* named "strCircularNumber" on the form?
2. is it visible?
3. are you sure the right form has the focus?
you might need a "doEvents" after the paste so that other after insert
events can fire.
If it were up to me, I'd dupe a record with an append query, or in VB I'd
just store a bunch of values in memory, goto New, and set values. (I wouldn't
use the clipboard.)
- Show quoted text -

Thanks for the suggestions. I definately have a control named
strCircularNumber in my form, and it is definately visible. I think
the form has the focus, since its title bar is highlighted, but just
to make sure, I added "Me.SetFocus" after my "DoCmd" instructions.
"DoEvents" doesn't seem to make a difference, but I got a very
unexpected result when I tried to do this another way with:

DoCmd.GoToControl Me.strCircularNumber

I got an error message that access couldn't find a control named "LI-
CF-2007-175", which happens to be the contents of my control named
strCircularNumber.

I also tried:  DoCmd.GoToControl Me.Controls([strCircularNumber]) but
I got the same result. There is nothing in my code setting
strCircularNumber to a variable. This is driving me crazy.  I would
greatly apprecaite any additional suggestions!

Alice- Hide quoted text -

- Show quoted text -

To follow up on my own post, when I do it the right way, with

DoCmd.GoToControl "strCircularNumber

I am back to getting the error message that "MS Office Access can't
move the control to strCircularNumber." I also tested whether my form
had the focus with

MsgBox Screen.ActiveForm.NAME

and it does.

I just can't believe that it can be this difficult. I have to be
missing something simple!

Alice

Alice
 
R

roger

Gotocontrol requires a string as a pararmeter

DoCmd.GoToControl "strCircularNumber"

The way you wote that command, VB thought you meant the contents of the
control, not the control itself which explains that error message.

might there be two things named "strCircularNumber" Is the contol source a
field named "strCircularNumber" ?

try renaming the control (maybe txtCircularNumber)




night_writer said:
1. are you sure you have a *control* named "strCircularNumber" on the form?
2. is it visible?
3. are you sure the right form has the focus?

you might need a "doEvents" after the paste so that other after insert
events can fire.

If it were up to me, I'd dupe a record with an append query, or in VB I'd
just store a bunch of values in memory, goto New, and set values. (I wouldn't
use the clipboard.)

hth
roger















- Show quoted text -

Thanks for the suggestions. I definately have a control named
strCircularNumber in my form, and it is definately visible. I think
the form has the focus, since its title bar is highlighted, but just
to make sure, I added "Me.SetFocus" after my "DoCmd" instructions.
"DoEvents" doesn't seem to make a difference, but I got a very
unexpected result when I tried to do this another way with:

DoCmd.GoToControl Me.strCircularNumber

I got an error message that access couldn't find a control named "LI-
CF-2007-175", which happens to be the contents of my control named
strCircularNumber.

I also tried: DoCmd.GoToControl Me.Controls([strCircularNumber]) but
I got the same result. There is nothing in my code setting
strCircularNumber to a variable. This is driving me crazy. I would
greatly apprecaite any additional suggestions!

Alice
.
 
N

night_writer

Gotocontrol requires a string as a pararmeter

DoCmd.GoToControl "strCircularNumber"

The way you wote that command, VB thought you meant the contents of the
control, not the control itself which explains that error message.

might there be two things named "strCircularNumber"  Is the contol source a
field named "strCircularNumber" ?

try renaming the control (maybe txtCircularNumber)



Thanks for the suggestions. I definately have a control named
strCircularNumber in my form, and it is definately visible. I think
the form has the focus, since its title bar is highlighted, but just
to make sure, I added "Me.SetFocus" after my "DoCmd" instructions.
"DoEvents" doesn't seem to make a difference, but I got a very
unexpected result when I tried to do this another way with:
DoCmd.GoToControl Me.strCircularNumber
I got an error message that access couldn't find a control named "LI-
CF-2007-175", which happens to be the contents of my control named
strCircularNumber.
I also tried:  DoCmd.GoToControl Me.Controls([strCircularNumber]) but
I got the same result. There is nothing in my code setting
strCircularNumber to a variable. This is driving me crazy.  I would
greatly apprecaite any additional suggestions!
Alice
.- Hide quoted text -

- Show quoted text -


thanks. I did find my trouble with the GoToControl command and fixed
it, but I still get the message that Access can't go to the control.
I don't have any duplicate name problems, and I get the same kind of
error message when I change the control I try to move to.

This has me defeated!

Alice
 
B

Barry A&P

Alice

I would have to agree with rogers earlier reply, Maybe you should look into
your technique for duplicating the record. and maybe post a little info on
where you are duplicating the record. and what action initiates the
duplication and maybe Why you are duplicating the record in the first place..

i use a append query to duplicate records like this
this is in the OnClick event of a button in form view with a subdatasheet.
please remember to backup first with any action queries and disable the
setwarning false the first time you run it so you get the proper prompts..

DoCmd.SetWarnings False
DoCmd.RunSQL _
"INSERT INTO tbl_yourTable ( [yourfield1], [yourfield2] ) SELECT " & _
Me.field1combo.Column(0) & ", " & Me.Field2Combo.Column(0)
DoCmd.SetWarnings True
DoCmd.Requery "YourSubformName"

Hope this helps
Barry


night_writer said:
1. are you sure you have a *control* named "strCircularNumber" on the form?
2. is it visible?
3. are you sure the right form has the focus?
you might need a "doEvents" after the paste so that other after insert
events can fire.
If it were up to me, I'd dupe a record with an append query, or in VB I'd
just store a bunch of values in memory, goto New, and set values. (I wouldn't
use the clipboard.)

:
My apologies for posting this again, but I think first post was tacked
on to a thread that was too old.
I am running into problems doing anything to a record in a form after
I've duplicated it.
Here is my code:
~~~~
'variable applies at modular level
blnDuplicate = True 'I DON'T RUN AN ONCURRENT EVENT SUBROUTINE
IF
TRUE
Me.ProjectID.Enabled = True 'I NEED TO ENABLE THIS FIELD,
OTHERWISE IT DOESN'T SEEM TO COPY
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
Me.strCircularNumber.SetFocus ' THIS IS WHERE IT BOMBS (SEE
BELOW)
blnDuplicate = False
~~~~
I need to move to strCircularNumber field, and then set
ProjectID.Enable to False and a few other things. The error I'm
getting is: "MS Office Access can't move the control to
strCircularNumber."
I've tried all sorts of things, and it appears that even though my
screen changes and appears to make the newly duplicated record the
current record, I just can't do anything with it! Other error messages
I've gotten trying various things make me think the record is not
being perceived as activated, even though it is current.
I am thinking there must be something very simple that I'm missing. I
just want to get control of this form again after I've appended the
record and I haven't been able to figure out how to do it!
Any help or advice would be greately appreciated.
Alice
.- Hide quoted text -
- Show quoted text -

Thanks for the suggestions. I definately have a control named
strCircularNumber in my form, and it is definately visible. I think
the form has the focus, since its title bar is highlighted, but just
to make sure, I added "Me.SetFocus" after my "DoCmd" instructions.
"DoEvents" doesn't seem to make a difference, but I got a very
unexpected result when I tried to do this another way with:

DoCmd.GoToControl Me.strCircularNumber

I got an error message that access couldn't find a control named "LI-
CF-2007-175", which happens to be the contents of my control named
strCircularNumber.

I also tried: DoCmd.GoToControl Me.Controls([strCircularNumber]) but
I got the same result. There is nothing in my code setting
strCircularNumber to a variable. This is driving me crazy. I would
greatly apprecaite any additional suggestions!

Alice- Hide quoted text -

- Show quoted text -

To follow up on my own post, when I do it the right way, with

DoCmd.GoToControl "strCircularNumber

I am back to getting the error message that "MS Office Access can't
move the control to strCircularNumber." I also tested whether my form
had the focus with

MsgBox Screen.ActiveForm.NAME

and it does.

I just can't believe that it can be this difficult. I have to be
missing something simple!

Alice

Alice
.
 
N

night_writer

Alice

I would have to agree with rogers earlier reply, Maybe you should look into
your technique for duplicating the record.  and maybe post a little info on
where you are duplicating the record. and what action initiates the
duplication and maybe Why you are duplicating the record in the first place..

i use a append query to duplicate records like this
this is in the OnClick event of a button in form view with a subdatasheet..
please remember to backup first with any action queries and disable the
setwarning false the first time you run it so you get the proper prompts...

DoCmd.SetWarnings False
DoCmd.RunSQL _
    "INSERT INTO tbl_yourTable ( [yourfield1], [yourfield2] ) SELECT " & _
        Me.field1combo.Column(0) & ", " & Me.Field2Combo.Column(0)
DoCmd.SetWarnings True
DoCmd.Requery "YourSubformName"

Hope this helps
Barry



night_writer said:
1. are you sure you have a *control* named "strCircularNumber" on the form?
2. is it visible?
3. are you sure the right form has the focus?
you might need a "doEvents" after the paste so that other after insert
events can fire.
If it were up to me, I'd dupe a record with an append query, or in VB I'd
just store a bunch of values in memory, goto New, and set values. (I wouldn't
use the clipboard.)
hth
roger
:
My apologies for posting this again, but I think first post was tacked
on to a thread that was too old.
I am running into problems doing anything to a record in a form after
I've duplicated it.
Here is my code:
~~~~
    'variable applies at modular level
    blnDuplicate = True  'I DON'T RUN AN ONCURRENT EVENT SUBROUTINE
IF
TRUE
    Me.ProjectID.Enabled = True  'I NEED TO ENABLE THIS FIELD,
OTHERWISE IT DOESN'T SEEM TO COPY
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.RunCommand acCmdPasteAppend
    Me.strCircularNumber.SetFocus ' THIS IS WHERE IT BOMBS (SEE
BELOW)
    blnDuplicate = False
~~~~
I need to move to strCircularNumber field, and then set
ProjectID.Enable to False and a few other things. The error I'm
getting is: "MS Office Access can't move the control to
strCircularNumber."
I've tried all sorts of things, and it appears that even though my
screen changes and appears to make the newly duplicated record the
current record, I just can't do anything with it! Other error messages
I've gotten trying various things make me think the record is not
being perceived as activated, even though it is current.
I am thinking there must be something very simple that I'm missing. I
just want to get control of this form again after I've appended the
record and I haven't been able to figure out how to do it!
Any help or advice would be greately appreciated.
Alice
.- Hide quoted text -
- Show quoted text -
Thanks for the suggestions. I definately have a control named
strCircularNumber in my form, and it is definately visible. I think
the form has the focus, since its title bar is highlighted, but just
to make sure, I added "Me.SetFocus" after my "DoCmd" instructions.
"DoEvents" doesn't seem to make a difference, but I got a very
unexpected result when I tried to do this another way with:
DoCmd.GoToControl Me.strCircularNumber
I got an error message that access couldn't find a control named "LI-
CF-2007-175", which happens to be the contents of my control named
strCircularNumber.
I also tried:  DoCmd.GoToControl Me.Controls([strCircularNumber]) but
I got the same result. There is nothing in my code setting
strCircularNumber to a variable. This is driving me crazy.  I would
greatly apprecaite any additional suggestions!
Alice- Hide quoted text -
- Show quoted text -
To follow up on my own post, when I do it the right way, with
    DoCmd.GoToControl "strCircularNumber
I am back to getting the error message that "MS Office Access can't
move the control to strCircularNumber." I also tested whether my form
had the focus with
    MsgBox Screen.ActiveForm.NAME
and it does.
I just can't believe that it can be this difficult. I have to be
missing something simple!

Alice
.- Hide quoted text -

- Show quoted text -


Thanks, Barry.

I agree that there must be a better way of doing what I'm doing, or I
wouldn't be having all these problems, but I still can't understand
what could possibly be preventing me from using VBA to move the focus
to a field in a visible, active form that includes a field of that
name.

To answer your questions, I am calling this routine from a button on a
form, frmCirculars. There are no subforms, but there are about 65
fields on the form, and that's why I was delighted to see the Access
wizard offer "duplicate record" as one of the options when creating my
button. I'm not very familiar with SQL or recordsets, and I figured
that would be the way to go, especially since the new record
immediately requires input from the user. And the duplication works
fine, except that after the record is duplicated, even though the the
form is active, it won't let me move to a named field on the form.

How can this be? It just doesn't make any sense that I can't interact
with the form (through code) after this simple transaction. The
entirity of my code for this subroutine is:

~~~~
'variable applies at modular level
blnDuplicate = True 'I DON'T RUN AN ONCURRENT EVENT SUBROUTINE IF
TRUE

Me.ProjectID.Enabled = True 'WON'T COPY OTHERWISE

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
Me.strCircularNumber.SetFocus ' THIS IS WHERE IT BOMBS

blnDuplicate = False
~~~~

I have to admit that I could probably have written and tested an SQL
INSERT statement, even for my horrible 65 fields, in the several days
I've been tearing my hair out over this, but I really thought there
would be some basic, simple answer to my problem, and I would just go
DUH! and fix it. If the experts are puzzled, the I have no choice but
to rethink my approach.

Thanks anyway.

Alice
 

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