Results 1 to 6 of 6
  1. #1
    thescottsman92 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    13

    Replace Function

    Hi



    I wonder if you can help, ive been stuck on this for a while

    I have a folder system that at the end of each folder system I have 4 folder (00,01,02,03) What I want to be able to do is replace the 01,02,03 with 00. I can get this function to work when I just use 01 but when I include other options lile 02 it does not work.

    I have tried allsorts including writing if statements for it


    Can anyone please help me and think of anything?


    thanks

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I can get this function to work when I just use 01 but when I include other options lile 02 it does not work.
    Can you post the formula that you have, so we can get a better idea of what you are trying to do?
    Are you trying to do this in a calculated field in a query, in VBA, or elsewhere?

  3. #3
    thescottsman92 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    13
    If MsgBox("Are you sure you want to edit this file?", vbOKCancel) = vbOK Then
    Me.txtarchivepath = Replace(Me.txtFolderPath, "02_3D Models", "00_Part Archive")
    Else
    If MsgBox("Are you sure you want to edit this file?", vbOKCancel) = vbOK Then
    Me.txtarchivepath = Replace(Me.txtFolderPath, "04_Production Drawings", "00_Part Archive")
    Else
    MsgBox "Folder Path cannot be found"
    Me.txtarchivepath = Null
    End If
    End If
    End Sub

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    This seems to work for me:
    Code:
        Me.Refresh
        If MsgBox("Are you sure you want to edit this file?", vbOKCancel) = vbOK Then
            If InStr(Me.txtFolderPath, "02_3D Models") > 0 Then
                Me.txtArchivePath = Replace(Me.txtFolderPath, "02_3D Models", "00_Part Archive")
            Else
                If InStr(Me.txtFolderPath, "04_Production Drawings") > 0 Then
                    Me.txtArchivePath = Replace(Me.txtFolderPath, "04_Production Drawings", "00_Part Archive")
                Else
                    MsgBox "Folder Path cannot be found"
                    Me.txtArchivePath = Null
                End If
            End If
        End If

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Here is an even better way using Arrays. If you have more values you are checking for, simply place them in the "myCheck" array, separated by commas. No other changes are needed to the code.
    Code:
        Dim myCheck
        myCheck = Array("02_3D Models", "04_Production Drawings")
        Dim i As Integer
        Dim myArchivePath As String
        
        Me.Refresh
    
    '   Loop through all entries in your array until you find a match
        For i = LBound(myCheck) To UBound(myCheck)
            If InStr(Me.txtFolderPath, myCheck(i)) > 0 Then
                myArchivePath = Replace(Me.txtFolderPath, myCheck(i), "00_Part Archive")
                Exit For
            End If
        Next i
        
    '   If a match was found, populate txtArchivePath
        If myArchivePath <> "" Then
            Me.txtArchivePath = myArchivePath
        Else
            MsgBox "Folder Path cannot be found"
            Me.txtArchivePath = Null
        End If

  6. #6
    thescottsman92 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2013
    Posts
    13
    thank you

    that has worked really well

    cheers

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with Replace Function...
    By redbull in forum Programming
    Replies: 5
    Last Post: 06-27-2013, 04:05 PM
  2. Error with Replace Function
    By Juan4412 in forum Queries
    Replies: 1
    Last Post: 09-30-2012, 05:48 PM
  3. Replies: 3
    Last Post: 06-07-2012, 07:05 AM
  4. Replace Function with Table Lookup
    By smurof in forum Access
    Replies: 1
    Last Post: 07-29-2011, 07:52 PM
  5. Applying a find/replace function
    By Arr in forum Programming
    Replies: 2
    Last Post: 10-12-2009, 12:28 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums