+ Reply to Thread
Results 1 to 7 of 7

Find/Replace not working

Hybrid View

narrowgate88 Find/Replace not working 06-07-2010, 02:15 PM
6StringJazzer Re: Find/Replace not working 06-07-2010, 04:08 PM
narrowgate88 Re: Find/Replace not working 06-07-2010, 04:13 PM
narrowgate88 Re: Find/Replace not working 06-07-2010, 04:19 PM
6StringJazzer Re: Find/Replace not working 06-07-2010, 06:27 PM
narrowgate88 Re: Find/Replace not working 06-08-2010, 09:20 AM
narrowgate88 Re: Find/Replace not working 06-08-2010, 09:31 AM
  1. #1
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Lincoln, IL
    MS-Off Ver
    365
    Posts
    242

    Question Find/Replace not working

    The portion of the code that replaces RESET with 1RESET, works fine on it's own, but not as part of this larger code. It doesn't error out, it just does nothing. Can someone point out what I'm missing? It's at almost the end of the code.

        Public Sub Generate_Accrued_PTO_Report()
    
    
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
    
    ' This code establishes values and formatting for the input boxes.
    '
        Dim MyInput As String
        Dim MyInput2 As String
    '    Dim MyInput3 As String
        Dim MyInput4 As String
    '    Dim MyInput5 As String
        Dim Message As String
        Dim TitlebarTxt As String
        Dim DefaultTxt As String
    
        Message = _
        "*  The Christian Village" & vbCrLf & _
        "*  Fair Havens Christian Home" & vbCrLf & _
        "*  Pleasant Meadows Christian Village" & vbCrLf & _
        "*  Lewis Memorial Christian Village" & vbCrLf & _
        "*  Hoosier Christian Village" & vbCrLf & _
        "*  Wabash Christian Retirement Center" & vbCrLf & _
        "*  Shawnee Christian Retirement Center" & vbCrLf & _
        "*  Washington Christian Village" & vbCrLf & _
        "*  Spring River Christian Village" & vbCrLf & _
        "*  Chicagoland Christian Village" & vbCrLf & _
        "*  Risen Son Christian Village" & vbCrLf & _
        "*  Heartland Christian Village" & vbCrLf & _
        "*  Hickory Point Christian Village" & vbCrLf & _
        "*  Senior Care Pharmacy Services" & vbCrLf & _
        "*  Corporate Office" & vbCrLf & _
        "*  Bridgeway Christian Village_Independent Living" & vbCrLf & _
        "*  Bridgeway Christian Village_Healthcare" & vbCrLf & _
        "*  Wabash Estates" & vbCrLf & _
        "*  Washington Village Estates"
        
        TitlebarTxt = "Location Selection"
        DefaultTxt = "Enter a location from the list above"
        
    ' This prompts the user for data that will be modified in the code below.
    '
        
        MyInput = InputBox(Message, TitlebarTxt, DefaultTxt)
        MyInput4 = InputBox("Enter File Folder (01_TCV)")
     '   MyInput3 = InputBox("Enter 2-Digit Facility Number (01)")
     '   MyInput5 = InputBox("Enter Cycle 2 Period Ending Date (2010-05-22)")
        MyInput2 = InputBox("Enter Period Ending Date (2010-05-29)")
    
    ' This code opens the Accrued PTO Query and changes the date to user specified date.
    '
        ChDir "U:\File Cabinet\K\Kronos Microsoft Queries\Accrued PTO Dollars"
        Workbooks.OpenDatabase Filename:= _
            "U:\File Cabinet\K\Kronos Microsoft Queries\Accrued PTO Dollars\Accrued_PTO_Dollars.dqy" _
            , CommandText:=Array( _
            "SELECT VP_PERSON.HOMELABORLEVELDSC1, VP_PERSON.HOMELABORLEVELDSC2, EmployeePay_Job_Curr.EmpNo, VP_PERSON.PERSONFULL" _
            , _
            "NAME, EmployeePay_Job_Curr.PayRate, VP_ACCRUALTRANV42.EFFECTIVEDATE, VP_ACCRUALTRANV42.ACCRUALTRANTYPENM, LEFT(Accr" _
            , _
            "ualTranAmount/60/60,6) AS 'AccrualTotal', VP_PERSON.HOMELABORLEVELNAME3  FROM WfcSuite.dbo.EmployeePay_Job_Curr Emp" _
            , _
            "loyeePay_Job_Curr, WfcSuite.dbo.VP_ACCRUALTRANV42 VP_ACCRUALTRANV42, WfcSuite.dbo.VP_PERSON VP_PERSON  WHERE VP_PER" _
            , _
            "SON.PERSONNUM = EmployeePay_Job_Curr.EmpNo AND VP_PERSON.PERSONNUM = VP_ACCRUALTRANV42.PERSONNUM AND ((VP_ACCRUALTR" _
            , _
            "ANV42.ACCRUALCODENAME='PTO') AND (VP_ACCRUALTRANV42.ACCRUALTRANTYPENM<>'CarryForward') AND (VP_ACCRUALTRANV42.ACCRU" _
            , _
            "ALTRANAMOUNT<>$0) AND (VP_ACCRUALTRANV42.EFFECTIVEDATE <='" & MyInput2 & "') AND (VP_PERSON.HOMELABO" _
            , _
            "RLEVELDSC1='" & MyInput & "'))  ORDER BY VP_PERSON.HOMELABORLEVELDSC2, VP_PERSON.HOMELABORLEVELNAME3, VP_PERS" _
            , "ON.PERSONFULLNAME, VP_ACCRUALTRANV42.EFFECTIVEDATE"), CommandType:=xlCmdSql _
            , ImportDataAs:=xlTable
        With ActiveWorkbook.Connections("Accrued_PTO_Dollars").ODBCConnection
            .BackgroundQuery = True
            .CommandText = Array( _
            "SELECT VP_PERSON.HOMELABORLEVELDSC1, VP_PERSON.HOMELABORLEVELDSC2, EmployeePay_Job_Curr.EmpNo, VP_PERSON.PERSONFULL" _
            , _
            "NAME, EmployeePay_Job_Curr.PayRate, VP_ACCRUALTRANV42.EFFECTIVEDATE, VP_ACCRUALTRANV42.ACCRUALTRANTYPENM, LEFT(Accr" _
            , _
            "ualTranAmount/60/60,6) AS 'AccrualTotal', VP_PERSON.HOMELABORLEVELNAME3" & Chr(13) & "" & Chr(10) & "FROM WfcSuite.dbo.EmployeePay_Job_Curr Emp" _
            , _
            "loyeePay_Job_Curr, WfcSuite.dbo.VP_ACCRUALTRANV42 VP_ACCRUALTRANV42, WfcSuite.dbo.VP_PERSON VP_PERSON" & Chr(13) & "" & Chr(10) & "WHERE VP_PER" _
            , _
            "SON.PERSONNUM = EmployeePay_Job_Curr.EmpNo AND VP_PERSON.PERSONNUM = VP_ACCRUALTRANV42.PERSONNUM AND ((VP_ACCRUALTR" _
            , _
            "ANV42.ACCRUALCODENAME='PTO') AND (VP_ACCRUALTRANV42.ACCRUALTRANTYPENM<>'CarryForward') AND (VP_ACCRUALTRANV42.ACCRU" _
            , _
            "ALTRANAMOUNT<>$0) AND (VP_ACCRUALTRANV42.EFFECTIVEDATE <='" & MyInput2 & "') AND (VP_PERSON.HOMELABO" _
            , _
            "RLEVELDSC1='" & MyInput & "'))" & Chr(13) & "" & Chr(10) & "ORDER BY VP_PERSON.HOMELABORLEVELDSC2, VP_PERSON.HOMELABORLEVELNAME3, VP_PERS" _
            , "ON.PERSONFULLNAME, VP_ACCRUALTRANV42.EFFECTIVEDATE")
            .CommandType = xlCmdSql
            .Connection = _
            "ODBC;DSN=WTK ;Description=WTK;UID=acrowe;APP=2007 Microsoft Office system;WSID=CHI102W;DATABASE=WfcSuite;Trusted_Connection=Yes"
            .RefreshOnFileOpen = False
            .SavePassword = False
            .SourceConnectionFile = ""
            .SourceDataFile = ""
            .ServerCredentialsMethod = xlCredentialsMethodIntegrated
            .AlwaysUseConnectionFile = False
        End With
        With ActiveWorkbook.Connections("Accrued_PTO_Dollars")
            .Name = "Accrued_PTO_Dollars"
            .Description = ""
        End With
        ActiveWorkbook.Connections("Accrued_PTO_Dollars").Refresh
    
    'This code auto replaces Reset with 1Reset
    '
            Columns("g:g").Select
            Selection.Replace What:="RESET", Replacement:="1RESET", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        
    ' This code formats the table data.
    
    
    
    
        
    'This code creates the pivot table.
    '
    '    Call Accrued_PTO_Pivot_Table
        
    'This code saves the report.
    '
    '    Call Accrued_PTO_Save
        
    '    Application.DisplayAlerts = True
    
        
    End Sub
    Last edited by narrowgate88; 06-07-2010 at 02:26 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,023

    Re: Find/Replace not working

    Your code opens another workbook, I think your replace code is looking in a different workbook than you intend. To clean this up I would qualify your range. Where is your code located? Is it associated with the worksheet you want to change, or is it in a Module? I would also avoid doing a Select for this. Try this:

    'This code auto replaces Reset with 1Reset
    '
            Worksheets("<worksheet name here">).Columns("g:g").Replace What:="RESET", Replacement:="1RESET", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    Last edited by 6StringJazzer; 06-07-2010 at 04:09 PM. Reason: grammar
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Lincoln, IL
    MS-Off Ver
    365
    Posts
    242

    Re: Find/Replace not working

    While waiting, I think I came to that conclusion as well. This code is in a module in the Personal Macro Workbook.

    I tried adding some code to save the output and then reopen, but it doesn't refresh the query data.

    I'll give you suggestion a try.

  4. #4
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Lincoln, IL
    MS-Off Ver
    365
    Posts
    242

    Re: Find/Replace not working

    That suggestion didn't work. Still show RESET instead of 1RESET.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,023

    Re: Find/Replace not working

    Quote Originally Posted by narrowgate88 View Post
    This code is in a module in the Personal Macro Workbook.
    Your environment seems a bit much for me to try to reproduce, but this last sentence made me realize that you also need to qualify the workbook. I assume that the active workbook is the one you need to modify, so try this. The first one looks in Personal.XLS because that's where the code is.

            ActiveWorkbook.Worksheets("<worksheet name here">).Columns("g:g").Replace What:="RESET", Replacement:="1RESET", LookAt:=xlPart, _

  6. #6
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Lincoln, IL
    MS-Off Ver
    365
    Posts
    242

    Re: Find/Replace not working

    Ok, I will give that a try.

  7. #7
    Forum Contributor
    Join Date
    05-13-2009
    Location
    Lincoln, IL
    MS-Off Ver
    365
    Posts
    242

    Re: Find/Replace not working

    That did not work either. So at this point, I feel like I'm either going to have to use 2 macros, or figure out a way to get the macro to import the data instead of dealing with the query.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1