Passing In Some Data to MS Access When Open Database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sedrick
    New Member
    • Aug 2011
    • 43

    #1

    Passing In Some Data to MS Access When Open Database

    I have two different databases. Both have initial login forms set up that is executed from the startup form. The first database can open the second when a button is clicked on the menu.

    I would like to be able to pass in the UserID from the first database to the second when that button is clicked, bypassing the login form in the second and using the UserID there in the second.

    I have looked at Interprocess Communications a little bit but have not seen any examples of how this might be done with one Access database calling up another.

    I do not want to create a database object of the second database in the first in order to write a value to a table, nor write to a temporary file unless there is some way to confirm that there was not a second user also opening it at the same time. Possibly, along this line of thought, I could somehow get the process ID of the second database when opened by the first and from the first, which is still running, write that process ID and the UserID to a table or temporary txt file; then have the second database identify it's own process ID and match it to that specific record to get the UserID.

    Any ideas? Thanks in advance for your input!
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    How, exactly, are you 'Opening' the 2nd Database?

    Comment

    • Sedrick
      New Member
      • Aug 2011
      • 43

      #3
      Using the Shell command, something like this:

      Code:
          
          stDBName = """C:\SomePath\db2.mdb"""
          stAppName = "Msaccess.exe " & stDBName 
          Call Shell(stAppName, vbNormalFocus)

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        There is one little Trick that I use when passing Data from one 'Office Component' to another and that is to use the System Registry. I'll write the Data from the Calling Application (Access in your case), then read it from the Receiving Application (also Access). The beauty and simplicity of this approach is that, since you are dealing with Office Components, you can use the built-in SaveSetting() Statement and GetSetting() Function to accomplish this. If you are interested, let me know and I'll show you how it can be done.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          You should find all you need in Invoking a Database From the Command Line. It includes an example of passing string data to the database and this is explained more fully in How to use command-line switches in Microsoft Access.

          Comment

          • Sedrick
            New Member
            • Aug 2011
            • 43

            #6
            The only problem with this approach I think is that potentially two simultaneous calls from two different users would tend to overwrite each other, right? How would the called database know which one to use?

            I understand that the Shell command returns the task ID of the called program. Is this the same as the process ID in the Windows Kernel? If I could call the Kernel then from the called database to identify the current process ID I could match up which is which.

            Comment

            • Sedrick
              New Member
              • Aug 2011
              • 43

              #7
              NeoPa,

              Thanks! That /cmd option with the "Command" statement should do the job very well!

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                I expect so. If not, there is more in that article you may find pertinent to your problem.

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32669

                  #9
                  As requested the other matters have been split into a separate thread Discussion: Working with Windows' Windows (hWnd etc).

                  Comment

                  Working...