Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004

    Unanswered: Can Forms / Controls in an Access Database be controlled remotely using VB?

    I'm not even sure if what I am trying to do is even possible.
    The following code works except for the lines with the ???? in front.
    The ???? indicates where this code works in a Module (code that is outside the forms class) locally in the Access program but not outside of the program in the separate VB control program I am working in.
    The table/recordset operations work just fine. I just am trying, once I open a particular Form, to populate the form with some data.... plus some other stuff but first things first.
    Sub Main()
    Dim dbs As Database
    Dim rst As Recordset
    Dim frm As Form
    Dim strDatabase As String
    Dim strA, strB As String
        strDatabase = "C:\DBTest\Concept.mdb"
        Set dbs = DBEngine.Workspaces(0).OpenDatabase(strDatabase)
        Set rst = dbs.OpenRecordset("Table1")
        With rst
            strA = !ID
            strB = !Field1
        End With
        DoCmd.OpenForm "Frm_TestForm", acNormal
        ???? Set frm = Forms!Frm_TestForm
        ???? frm!txtControlTest.Text = "foobar"
        DoCmd.Close acForm, "Frm_TestForm"
    End Sub
    When the code runs it opens the database and recordset just fine. The variables contain the correct information and the DoCmd.OpenForm works (although I don't understand why... unless it's because within this procedure opening a database has somehow set up an "environment" that the DoCmd knows about.)

    The program breaks, hiccups when it comes to theSet frm = Forms!Frm_TestForm statement Runtime Error 13 IT does not know about "Forms!" I was HOPING that since the DoCmd could open the form that "Froms!" would work too! LOL

    Since I can't get past the Set statement I don't know if the next statement would bomb also.

    Continuing on, if I comment the two questionable lines the form closes and the procedure exits normally.

    Does anyone know how the syntax, (if it's even possible) necessary to open a Form and then access the controls and even public sub/functions in the form class.
    I tried another approach THAT DID NOT WORK AT ALL
        Set appAccess = CreateObject("Access.Application")
        appAccess.OpenCurrentDatabase ("C:\DBTest\Concept.mdb")
        appAccess.DoCmd.OpenForm "Frm_TestForm"
    In this next example, the Form never opened up. I was thinking that somehow that this might have allowed me to get into the Forms Objects/Collections and could somehow be referenced.

    If someone has another approach entirely I'm open to that as well
    Gee, I hope I haven't confused this issue.
    many thanks in advance,

    The following code section are various code snippets of the functionality that I use in Access that I would like to do remotely while using VB to control the Access application. I don't know if it's even close to being possible to achieve that level of control. I have been able remote control Excell spreadsheets, down to the cell and cell property level but the mechanism for doing that is slightly different than working with Access)

    Forms!Frm_ProgressForm.frm_display_progress inLevel 
    Forms![Frm_ProgressForm]("lbl" & inPos).Caption = inCaption   
    If CalFormIsLoaded("Frm_CalendarAppointments") Then
        Forms![Frm_CalendarAppointments].resetAppointmentsCalendar inMonth
    End If
    If IsLoaded("Frm_ProgressForm") = True Then
             For intIndex = 1 To inNumber
                strLocation = "chk" & Trim(Str(intIndex))
                Forms![Frm_ProgressForm](strLocation).Visible = True
                strLocation = "lbl" & Trim(Str(intIndex))
                Forms![Frm_ProgressForm](strLocation).Visible = True
            Next intIndex
    If the software doesn't work then I suggest that you call the Support Team... I'm a Developer!

    I Like Pizza Alot!

  2. #2
    Join Date
    Nov 2004


    I don't really understand why would you do this instead of doing it all in VB

    I have never used DoCmd but try this
    Set frm = DoCmd.OpenForm "Frm_TestForm", acNormal
    frm.txtControlTest.Text = "foobar"
    about the other approach you are using instead of using create object add the reference directly to the project I think this way you'll have the autoListMembers for access(not sure though)
    to err is human ; to really mess things up requires a computer

Posting Permissions

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