Hello,
I'm trying to incorporate some code that was used in an old database (access 2003 but everything works in 2007) by someone who no longer works with me that utilizes sendkeys to send employee (agent) exceptions into their schedule which is in a different application. The old database works fine as is however I'm making a database for training and trying to use the code with mine and just started learning VBA and could use some assistance.
The code below is what I'm trying to fix and the part in red is what it use to be and the code immediately below that in blue is my failed attempt to fix it. I should note that the original code was meant to process one Agent_ID and one exception at a time whereas I'm trying to process Multiple Agent_ID's based off of two yes/no fields for one exception. Edit: guess color tags don't work so I'm underlining as well.
The error I'm currently receiving is run-time error 2046, the command or action 'Copy' isn't available now.
If anyone feels generous I'm wanting to eventually convert this from sendkeys to SendMessage to kind of future proof it and make it more reliable.
I also tried replacing the DoCmd.RunComman d acCmdCopy at the top of my code to DoCmd.RunComman d acCmdSelectReco rd and it too errors out and stops where it's in my other application with the search window open correctly set to search Agent_ID but it's pasting "DoCmd.RunComma nd acCmdSelectReco rd" as the Agent_ID to pull up. I'm thinking I need major help as I don't know which to use if either of the two and from the Select Record it seems like I'll need to step through each Agent_ID and exception one at a time which I'll be happy to give it a shot but need help past this part first.
Thanks in advance!
I'm trying to incorporate some code that was used in an old database (access 2003 but everything works in 2007) by someone who no longer works with me that utilizes sendkeys to send employee (agent) exceptions into their schedule which is in a different application. The old database works fine as is however I'm making a database for training and trying to use the code with mine and just started learning VBA and could use some assistance.
The code below is what I'm trying to fix and the part in red is what it use to be and the code immediately below that in blue is my failed attempt to fix it. I should note that the original code was meant to process one Agent_ID and one exception at a time whereas I'm trying to process Multiple Agent_ID's based off of two yes/no fields for one exception. Edit: guess color tags don't work so I'm underlining as well.
The error I'm currently receiving is run-time error 2046, the command or action 'Copy' isn't available now.
If anyone feels generous I'm wanting to eventually convert this from sendkeys to SendMessage to kind of future proof it and make it more reliable.
Code:
Private Sub cmdEnterTRNG_Click() Dim db As DAO.Database Dim rs As DAO.Recordset Dim strSQL As String Dim intStartMinute As Integer Dim intLength As Integer Dim intLunchLength As Integer Dim intException As Integer Dim intError As Integer Dim strCopy As String Dim strWholeSchedule As String Dim blManual As Boolean 'Me.txtCopy = Null 'Grabs Agent_ID '[COLOR="Red"][U]Me.ACDID.SetFocus[/U][/COLOR] ' Original Code used 'My new Code to fix [COLOR="BLUE"][U]strSQL = "Select [tblCE_AddTemp].[Agent_ID] " & _ "From [tblCE_AddTemp] " & _ "Where (([tblCE_AddTemp.LeaveBlank] = 0 And [tblCE_AddTemp.Missed] = 0))" Set db = CurrentDb() Set rs = db.OpenRecordset(strSQL)[/U][/COLOR] DoCmd.RunCommand acCmdCopy 'Finds Agent_ID in IEX SendKeys ("%{TAB 1}"), True SendKeys ("+{F4 1}"), True SendKeys ("%{N 1}"), True SendKeys ("{UP 3}"), True SendKeys ("{TAB 1}"), True SendKeys ("+{END 1}"), True SendKeys ("^{V 1}"), True SendKeys ("{ENTER 1}"), True SendKeys ("{TAB 6}"), True SendKeys ("{ENTER 1}"), True 'Copies schedule from IEX SendKeys ("%{E 1}"), True SendKeys ("{DOWN 5}"), True SendKeys ("{ENTER 1}"), True 'Returns to Access SendKeys ("%{TAB 1}"), True strWholeSchedule = Clipboard2Text() 'Finds exception to key in IEX 'strSQL = "SELECT tbl_All_Code_Types.Qualifier, tbl_All_Code_Types.Absense_Type " & _ '"FROM tbl_All_Code_Types " & _ ' "WHERE (((tbl_All_Code_Types.Absense_Type)=" & Chr(34) & Me.Exception_Code & Chr(34) & '"));" ' Set db = CurrentDb 'Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot) ' If rs.RecordCount = 1 Then intException = Val(cboTTVTRNG.Value) ' Else 'strError = "Exception not in avialble list" 'MsgBox "Please Manualy Key This. (" & strError & ")" 'rs.Close: db.Close 'Set rs = Nothing: Set db = Nothing 'Sleep (1) 'Exit Sub 'End If rs.Close: db.Close Set rs = Nothing: Set db = Nothing 'Creates the exception to be pasted into IEX intStartMinute = DateDiff("n", #12:00:00 AM#, Me.txtTTVTRNGStart.Value) intLength = DateDiff("n", Me.txtTTVTRNGStart.Value, Me.txtTTVTRNGEnd.Value) strCopy = intStartMinute & "|" & intLength & "|" & intException 'Verifies if the new exception will fit in the current schedule varschedule = Split(strWholeSchedule, "|") x = Null x = Split(FindLunch(strWholeSchedule), ",") intLunchLength = Val(x(2)) y = Null y = Split(strWholeSchedule, "|") 'Can't remember what this one does If y(1) = 0 Then blManual = True strError = "ERROR 2" End If 'Checks to make sure there is a lunch in the schedule 'Braced Out for testing 11/11/2008 ' If x(0) = 0 And x(1) = 0 And x(2) = 0 Then ' blManual = True ' intError = 3 ' End If ' If blManual = True Then ' MsgBox "Please Manualy Key This. e(" & intError & ")" ' Sleep (1) ' ToggleNumLock (True) ' Sleep (1) ' Exit Sub ' End If If intLength = varschedule(1) And varschedule(1) >= 480 Then Debug.Print 'Builds exception before lunch strCopy = Val(varschedule(0)) & "|" & Val(varschedule(1)) & "|" & intException & "," & Val(varschedule(0)) & "," & Val(x(1)) - Val(varschedule(0)) & "," 'Builds Lunch strCopy = strCopy & Val(x(0)) & "," & Val(x(1)) & "," & Val(x(2)) & "," 'Builds exception after lunch strCopy = strCopy & intException & "," & Val(x(1)) + Val(x(2)) & "," & _ (Val(varschedule(1)) - Val(x(2))) - (Val(x(1)) - Val(varschedule(0))) 'Tacks on the junk at the end of the schedule strCopy = strCopy & "|-1|0" Me.txtTTVTRNGStart.Value = DateAdd("n", Val(varschedule(0)), #12:00:00 AM#) Me.txtTTVTRNGEnd.Value = DateAdd("n", Val(varschedule(1)), Me.txtTTVTRNGStart.Value) Me.txtTRNGDuration = DateDiff("n", Me.txtTTVTRNGStart.Value, Me.txtTTVTRNGEnd.Value) Else blManual = False If intStartMinute < Val(varschedule(0)) Or _ intStartMinute + intLength > Val(varschedule(0)) + Val(varschedule(1)) Then blManual = True strError = "OUTSIDE SHIFT" End If ' If Val(varschedule(1)) > 600 + intLunchLength And intStartMinute + intLength > Val(varschedule(0)) + intLunchLength + 480 Then ' blManual = True ' strError = "SHIFT GREATER THAN 10HOURS" ' End If ' If Val(varschedule(1)) < 480 Then ' blManual = True ' strError = "SHIFT LESS THAN 8 HOURS" ' End If If blManual = True Then MsgBox "Please Manualy Key This. (" & strError & ")" 'Sleep (1) Exit Sub End If End If 'Checks to see if there is any overlaps - This part doesn't work completely yet 'Call DisectSchedule(strWholeSchedule) 'Collects the exception to paste into IEX Call ClearClipboard Text2Clipboard (strCopy) 'Goes back to IEX and pastes info SendKeys ("%{TAB 1}"), True SendKeys ("%{E 1}"), True SendKeys ("{DOWN 3}"), True SendKeys ("{ENTER 1}"), True '----------------------- 'Sleep (5) 'SendKeys ("%{E 1}"), True 'SendKeys ("{DOWN}"), True 'SendKeys ("{ENTER 1}"), True 'Sleep (3) 'SendKeys ("%{E 1}"), True 'SendKeys ("{DOWN 3}"), True 'SendKeys ("{ENTER 1}"), True '----------------------- 'Turns NumLock On 'ToggleNumLock (True) End Sub
Thanks in advance!
Comment