Pass Control to Access From VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markryan57
    New Member
    • Feb 2007
    • 21

    #16
    Thank you Neo for the CODE tag explanation. I will do that from this point forward.

    Mary,
    Um (scratching head) - I did plug in the objAccess.Quit code you sent, it does what I suspected it would. It closes the application before it opens. I am going to assume that VB stays in control of Access no matter what Access does.

    I will look further into the opencurrentdata base object - I think I need to find out how to open an Access instance and give control to Access.

    thank you for your help, I will keep trying.

    You folks are wonderful

    Kindest regards,
    Mark

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #17
      Mark,
      Did you look through the Tutorial (Linked in post #7)?
      Repeated here (Application Automation).

      Comment

      • markryan57
        New Member
        • Feb 2007
        • 21

        #18
        Mary,

        I plugged in the code changes you sent also (sorry didn't mention that earlier), I get the error message "Active X component can't create object". I opened the project references to see it I had the MS ActiveX Data Objects Recordset Lib and I do.

        Sorry - I don't want you folks to spend much more time on this, you have been so helpful up till now.

        thank you for your help thus far.

        best regards,
        mark

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #19
          The most important library for this is the
          Microsoft Access x.x Object Library.

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #20
            I changed createObject to get object. You could change it back and see if it makes any difference.

            Code:
            Set objAccess = GetObject(, "Access.Application")
            to

            Code:
            Set objAccess = CreateObject(, "Access.Application")

            Comment

            • markryan57
              New Member
              • Feb 2007
              • 21

              #21
              Thank you Mary for your help on this. It will remain an open issue I think until I am able to look into how access and vb work together using opencurrentdata base.

              I will let everyone know if and when a solution is found..

              kindest regards,

              mark

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32633

                #22
                Originally posted by NeoPa
                The most important library for this is the
                Microsoft Access x.x Object Library.
                Mark, Did you see this post?
                I'm not trying to pester, but it's not like you to ignore it if you'd seen it.

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #23
                  Originally posted by markryan57
                  I have a VB program that acts as an interface for different functions - I am trying to run an Access program, where (for now) control is passed to Access from VB. When Access is done and the db is closed - the VB app cannot open another instance of Access (which is necessary).

                  How do I launch Access from VB and pass control to Access?
                  You did not mention if you explicitly Quit the 1st Instance of Access via the Object Variable Reference. Did you?

                  Comment

                  • markryan57
                    New Member
                    • Feb 2007
                    • 21

                    #24
                    Originally posted by NeoPa
                    Mark, Did you see this post?
                    I'm not trying to pester, but it's not like you to ignore it if you'd seen it.
                    Hey Neo, Yes I did see that. The program would not run at all unless that was in the project references. Thanks friend

                    you da man!

                    Comment

                    • ADezii
                      Recognized Expert Expert
                      • Apr 2006
                      • 8834

                      #25
                      As previously stated by NeoPa, I don't think that the OpenCurrentData base Method can stand alone by itself. Doesn't it have to be preceeded by an Application Object?

                      Comment

                      • markryan57
                        New Member
                        • Feb 2007
                        • 21

                        #26
                        Originally posted by ADezii
                        You did not mention if you explicitly Quit the 1st Instance of Access via the Object Variable Reference. Did you?
                        Adezil,
                        if you mean did I close the Access application once done, yes I do. Do I close the Access App from VB, no. If I put in the objAccess.quit in the Access app it really never opens, as VB has control all the time.

                        What I am trying to learn through research is how can I open an instance of Access (and work within it) and release VB's control over Access.

                        Thanks Adezil,

                        Kindest Regards,

                        Mark

                        Comment

                        • MMcCarthy
                          Recognized Expert MVP
                          • Aug 2006
                          • 14387

                          #27
                          What ADezii means is ..

                          This is your code:
                          Code:
                              OpenCurrentDatabase "Folder path\Template.mdb"
                              objAccess.Visible = True
                          This is my code:

                          Code:
                               
                             objAccess.OpenCurrentDatabase "Folder path\Template.mdb"
                              objAccess.Visible = True

                          Comment

                          • markryan57
                            New Member
                            • Feb 2007
                            • 21

                            #28
                            Originally posted by mmccarthy
                            What ADezii means is ..

                            This is your code:
                            Code:
                                OpenCurrentDatabase "Folder path\Template.mdb"
                                objAccess.Visible = True
                            This is my code:

                            Code:
                                 
                               objAccess.OpenCurrentDatabase "Folder path\Template.mdb"
                                objAccess.Visible = True
                            My bad, Yes I have tried (in desperation) both ways, i.e., with objAccess in front and without. I see the reasoning behind, just can't get over that hump - thanks Mary, sorry ADezii - a blonde moment

                            Comment

                            • Killer42
                              Recognized Expert Expert
                              • Oct 2006
                              • 8429

                              #29
                              Hi all.

                              Personally I've gotten somewhat lost in this thread, so this idea may be overly simplistic and not much help. Nevertheless...

                              Have you considered whether your situation actually prohibits you simply "shelling" to the database in question? In other words, starting it up as a separate application, rather than through automation.

                              Comment

                              • markryan57
                                New Member
                                • Feb 2007
                                • 21

                                #30
                                Okay folks i found a way around the problem, just for information purposes. I put a msgbox in and checked the return code for a 1 then did the objAccess.Quit if they select OK.

                                Code:
                                   
                                    Dim objAccess As Object
                                    Set objAccess = CreateObject("Access.Application")
                                    objAccess.OpenCurrentDatabase "pathtodatabase", True
                                    objAccess.Visible = True
                                    lblMessageArea.ForeColor = vbRed
                                    lblMessageArea.Caption = "Database Run Complete - Go to Step 2."
                                    Label24.Visible = True
                                    Else
                                        MsgBox "Problem - Please Select Name - before continuing...", vbOKOnly, "TA Inforce Error"
                                        Exit Sub
                                    End If
                                        tstmsg = MsgBox("Are you done?", vbOKCancel + vbExclamation)
                                        If tstmsg = 1 Then
                                            objAccess.Quit
                                        End If
                                 Set objAccess = Nothing
                                not the cleanest method, but it works well..

                                Thanks for everyone's time - I have learned a great deal. I would like to thank all the little people ...... no wait.. that's my acceptance speech.

                                Kindest regards,
                                Mark

                                Comment

                                Working...