Results 1 to 14 of 14

Thread: Two databases in one project ...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Two databases in one project ...

    Hi,

    I have two MS Access databases (Sales2006.mdb & Sales2007.mdb) and two Checkboxes (CheckSales2006 & CheckSales2007).

    What I need is, when I Select CheckSales2006 I should get the data from Sales2006.mdb and when I Select CheckSales2007 I should get the data from Sales2007.mdb.

    I have the code in a module like the following:

    VB Code:
    1. Public Sub data_connect()
    2. Dim path As String
    3. path = App.path & "\[Highlight=VB]Database2006.mdb
    "
    db.CursorLocation = adUseClient
    db.Open "Provider=microsoft.jet.oledb.4.0;persist security info=false;data source=" & path & ";"
    End Sub[/Highlight]

    How to modify the code accordingly?

    Regards,

    Margaret

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Two databases in one project ...

    Is the option permanent for one full session or will it change in between...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Two databases in one project ...

    Quote Originally Posted by ganeshmoorthy
    Is the option permanent for one full session or will it change in between...
    Yes, it need to be changed in between.

    Margaret

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Two databases in one project ...

    Can both be open at the same time?

    If not, then I would suggest using option buttons rather than checkboxes.

    There are a couple of things that come to mind.

    The first is to use a command button (perhaps called cmdConnect) which evaluates which checkbox/option button is selected, and issues the appropriate connect string for that database.

    Another, and one that I'm not overly fond of, but is nonetheless and possibility, is to place the appropriate connect string in the click event of the checkbox/option button so that the connection is made the instant you select the control. Again, I'm not wild about this as it is possible the user could select the wrong one by mistake.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Two databases in one project ...

    I would say that there should only be one database file.

    In the appropriate table(s), simply add an extra field that contains the date/year (if you dont have one already), and use a Where clause to limit the data that is displayed in each case.

    This wont slow things down noticeably, and will be less prone to problems. Switching connections while recordsets are open is guaranteed to lead to issues - most likely data corruption and/or program errors.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Two databases in one project ...

    Quote Originally Posted by Hack
    Can both be open at the same time?

    If not, then I would suggest using option buttons rather than checkboxes.

    There are a couple of things that come to mind.

    The first is to use a command button (perhaps called cmdConnect) which evaluates which checkbox/option button is selected, and issues the appropriate connect string for that database.
    Thanks. Then, I would prefer command button using option buttons. Please help me with the code.

    Margaret.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Two databases in one project ...

    You already know the code.

    You have two databases.

    You will need two connection strings, one for each database.

    In the connect button, just put
    VB Code:
    1. Private Sub cmdConnect_Click()
    2. If Option1.Value = True Then
    3.    'run code to connect to 2006 database
    4. Else
    5.    'run code to connect to 2007 database
    6. End If
    You didn't answer my question about whether the two databases can be open at the same time. If they can not, then include code to disconnect before you run the code to connect.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Two databases in one project ...

    Quote Originally Posted by Hack
    You didn't answer my question about whether the two databases can be open at the same time. If they can not, then include code to disconnect before you run the code to connect.
    Now I use only Database2006, but in January I will use Database2007 and freqently I need to get the details from Database2006 as well.

    Margaret

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Two databases in one project ...

    So what is the reason for two separate databases, rather than just one as I described above?

    (are you planning to re-write this app every year to work with the new database files?)

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Two databases in one project ...

    Quote Originally Posted by si_the_geek
    So what is the reason for two separate databases, rather than just one as I described above?

    (are you planning to re-write this app every year to work with the new database files?)
    Excellent questions.

    With each passing year does the prior year database become an archive database?

    How many records, typically, will your database have after one calendar year?

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Two databases in one project ...

    Quote Originally Posted by Hack
    Excellent questions.

    With each passing year does the prior year database become an archive database?

    How many records, typically, will your database have after one calendar year?
    Since I am a learner I can't create any complex projects. That is why I will create a new database with name Database2007 and copy all the table structures of Database2006 to it. So that it will be easy for me and no need to create a new project for that.

    Margaret

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Two databases in one project ...

    Ok, but going forward, which is where I believe si_the_geek was headed, what will happen in December of 2007....will you be creating a new 2008 database and rewriting your project to accommodate that?

  13. #13
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Two databases in one project ...

    Indeed.. and the suggestion I made will mean you only need to change a few lines of code - which is less work than you are currently doing to create/use the new database!

    We understand that you may not be able to do it all on your own yet, but we can help you.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Two databases in one project ...

    Quote Originally Posted by si_the_geek
    Indeed.. and the suggestion I made will mean you only need to change a few lines of code - which is less work than you are currently doing to create/use the new database!

    We understand that you may not be able to do it all on your own yet, but we can help you.
    Hi, Thanks a lot for your kind suggestion and for the usual help.

    Margaret

Posting Permissions

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



Click Here to Expand Forum to Full Width