If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
acCmdCopy is not working
Hi
I am using access 2003. I need to copy the contents of a control (text box, called ID) from a form so I can paste the contents of the field in another application. I am trying to do this so whenever I move to a new record, using the Record Navigation Buttons, the ID field is copied to the clipboard. I am using the following: Me!ID.SetFocus DoCmd.RunCommand acCmdCopy This seems to work fine when I use the code in a button or in a (On Got Focus) or (On Lost Focus) procedures. The problem is that when I use it in the (On Current) event of a Form, it will give me the following error (to me it is equivalent to the blue screen of death): Run-Time error '2046': The Command or Action 'Copy' isn't available now I have tried so many things and been looking around on the MS website and other independant forums without much luck. My questions a 1) Why the code doesn't work through the (On Current) event only 2) Is there a way to solve the problem Thank you in advance |
#2
|
|||
|
|||
acCmdCopy is not working
My guess is that you have the "Behavior Entering Field" property of the
database set to "Go to start of field" instead of "Select entire field". You can change this property through the Options menu, Advanced, Editing in Office 2007, if you want. Personally, I prefer the start of field option, so in order to get it to work in the current event, you are going to actually have to select the text in that field. Try: me.ID.SetFocus me.ID.SelStart = 0 me.ID.SelLength = Len(me.ID) DoCmd.RunCommand acCmdCopy ---- HTH Dale "KiwiMan" wrote: Hi I am using access 2003. I need to copy the contents of a control (text box, called ID) from a form so I can paste the contents of the field in another application. I am trying to do this so whenever I move to a new record, using the Record Navigation Buttons, the ID field is copied to the clipboard. I am using the following: Me!ID.SetFocus DoCmd.RunCommand acCmdCopy This seems to work fine when I use the code in a button or in a (On Got Focus) or (On Lost Focus) procedures. The problem is that when I use it in the (On Current) event of a Form, it will give me the following error (to me it is equivalent to the blue screen of death): Run-Time error '2046': The Command or Action 'Copy' isn't available now I have tried so many things and been looking around on the MS website and other independant forums without much luck. My questions a 1) Why the code doesn't work through the (On Current) event only 2) Is there a way to solve the problem Thank you in advance |
#3
|
|||
|
|||
acCmdCopy is not working
Thank you Dale
The "Behavior entering field" is actually set to "Select entire field". I tried your suggestion but unfortunately it didn't work and gave the same error message. I tried your code with a command button and it works fine. As before, it is only when I put it in the "On Current" of a form that it generates the error. The problem is clearly related to the module it is in, and it doesn't work with On Current. Probably because of the change of the record. It is strange because the record is changed and the field is selected but Access can't copy it. If I copy it manually it works. I wonder if it has something to do with 'automation'? Any ideas? Dale Fye wrote: My guess is that you have the "Behavior Entering Field" property of the database set to "Go to start of field" instead of "Select entire field". You can change this property through the Options menu, Advanced, Editing in Office 2007, if you want. Personally, I prefer the start of field option, so in order to get it to work in the current event, you are going to actually have to select the text in that field. Try: me.ID.SetFocus me.ID.SelStart = 0 me.ID.SelLength = Len(me.ID) DoCmd.RunCommand acCmdCopy ---- HTH Dale Hi I am using access 2003. [quoted text clipped - 23 lines] Thank you in advance -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...arted/200908/1 |
#4
|
|||
|
|||
acCmdCopy is not working
KiwiMan,
I've done a little playing around, and I cannot tell you why it is doing what it is, but I'm thinking it has to be some sort of a timing issue, although I inserted a pause after the SelLength line and before the cmdCopy and it still did not work. Interestingly, whenever I put a breakpoint in my code, either before the Copy command or in the error handler, and then used F5 to execute the rest of the code, it works fine. Sorry I couldn't be more help. Would appreciate knowing what you figure out when you do so. ---- Dale "KiwiMan via AccessMonster.com" wrote: Thank you Dale The "Behavior entering field" is actually set to "Select entire field". I tried your suggestion but unfortunately it didn't work and gave the same error message. I tried your code with a command button and it works fine. As before, it is only when I put it in the "On Current" of a form that it generates the error. The problem is clearly related to the module it is in, and it doesn't work with On Current. Probably because of the change of the record. It is strange because the record is changed and the field is selected but Access can't copy it. If I copy it manually it works. I wonder if it has something to do with 'automation'? Any ideas? Dale Fye wrote: My guess is that you have the "Behavior Entering Field" property of the database set to "Go to start of field" instead of "Select entire field". You can change this property through the Options menu, Advanced, Editing in Office 2007, if you want. Personally, I prefer the start of field option, so in order to get it to work in the current event, you are going to actually have to select the text in that field. Try: me.ID.SetFocus me.ID.SelStart = 0 me.ID.SelLength = Len(me.ID) DoCmd.RunCommand acCmdCopy ---- HTH Dale Hi I am using access 2003. [quoted text clipped - 23 lines] Thank you in advance -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...arted/200908/1 |
#5
|
|||
|
|||
acCmdCopy is not working
Thank you Dale
At least I know now that it is not my computer or my version of Access. I will keep trying. I will try to put a 'break' but I must find a way to continue execution after that. Will post if I resolve the issue. Kiwiman Dale Fye wrote: KiwiMan, I've done a little playing around, and I cannot tell you why it is doing what it is, but I'm thinking it has to be some sort of a timing issue, although I inserted a pause after the SelLength line and before the cmdCopy and it still did not work. Interestingly, whenever I put a breakpoint in my code, either before the Copy command or in the error handler, and then used F5 to execute the rest of the code, it works fine. Sorry I couldn't be more help. Would appreciate knowing what you figure out when you do so. ---- Dale Thank you Dale [quoted text clipped - 35 lines] Thank you in advance -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...arted/200908/1 |
#6
|
|||
|
|||
acCmdCopy is not working
Current event will clear the setfocus, so you can't do a text copy.
I have test this code, seems to work on the current event. Option Compare Database Option Explicit Dim stroldValue As String Private Sub Form_Current() If Not Me.NewRecord Then stroldValue = Me.Text0.OldValue End If If Me.NewRecord Then Me.Text0 = stroldValue Me.Text0.SetFocus DoCmd.RunCommand acCmdCopy Me.Undo End If End Sub KiwiMan wrote: Thank you Dale At least I know now that it is not my computer or my version of Access. I will keep trying. I will try to put a 'break' but I must find a way to continue execution after that. Will post if I resolve the issue. -- Please Rate the posting if helps you. Message posted via http://www.accessmonster.com |
Thread Tools | |
Display Modes | |
|
|