×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Choose Backend using VBA

Choose Backend using VBA

Choose Backend using VBA

(OP)
I asked this in another section so apologies for trying again here.

I want to be able to allow a user to switch between two backends with identical structures but different date ranges, so

\\BackendData\CurrentOrders.mdb
\\BackendData\ArchiveOrders.mdb

There are several posts on a similar theme but I haven't been able to adapt them.

Help much appreciated, as ever.

RE: Choose Backend using VBA

(OP)
Splendid, thanks Combo, this allowed me to modify so I could open CurrentOrders normally but allow users to switch to ArchiveOrders with a single click.

RE: Choose Backend using VBA

(OP)
This is the modified code, used on one command button to switch to the Archive. Another button uses the same to code to connect to a CurrentData.mdb backend. Works a treat.

CODE -->

Private Sub cmdCurrentBackend_Click()

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim LnkDataBase As String
Dim strTable As String
    
    LnkDataBase = "\\MOAKBBTERM16" & "\" & "Database" & "\" & "Archive.mdb "
    Set dbs = CurrentDb()

    For Each tdf In dbs.TableDefs
        If Len(tdf.Connect) > 1 Then 'Only relink linked tables
            If tdf.Connect <> ";DATABASE=" & LnkDataBase Then 'only relink tables if the are not linked right
                If Left(tdf.Connect, 4) <> "ODBC" And Left(tdf.Connect, 5) <> "Excel" Then 'Don't want to relink any ODBC tables
                    strTable = tdf.Name
                    dbs.TableDefs(strTable).Connect = ";DATABASE=" & LnkDataBase
                    dbs.TableDefs(strTable).RefreshLink
                End If
            End If
        End If
    Next tdf
    
End Sub 

A supplementary question is how to stop people inadvertently using the Archive backend to create new orders, since the data would obviously not then appear in the Current backend. I'll ask about this in a separate post.

Thanks again for quick responses.

RE: Choose Backend using VBA

" Another button uses the same to code to connect to a CurrentData.mdb backend"
I hope you do not copy-paste this code just to change the name of your mdb ponder


---- Andy

There is a great need for a sarcasm font.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close