none
Using Visual Studio VB.NET to Change Access Database Form Textbox By Microsoft Access Interop RRS feed

  • Question

  • To anyone that can help with this issue

    I've recently began coding in VB.NET after a couple of years of basic programming in VBA (particularly Access). 

    I am regularly running subroutines on Access databases and I'm trying to recode the subroutines that I use to Visual Studio VB.NET.

    However, the problem that I am facing is this. I need to change the value in a textbox on an Access Form in order for other queries/ reports to function. 

    In Microsoft Access VBA the command would be Forms![Form1].[Text0].value = (Some string or value)

    The code that I have is this, using the Microsoft Access Interop and Microsoft Access 16.0 Object Library

    Dim FilePath As String = "" 'FilePath of database omitted
    		Dim oAccess As New Microsoft.Office.Interop.Access.Application
    
    		oAccess.OpenCurrentDatabase(FilePath)
    
    		oAccess.Visible = True
    
    		oAccess.DoCmd.OpenForm("Form1", Microsoft.Office.Interop.Access.AcFormView.acNormal)

    The Form in question is called "Form1" and the textbox that i am changing is called "Text0"


    Sunday, February 19, 2017 6:18 PM

All replies

  • Hi,

    Hope this code can help you.

      Dim fom As Microsoft.Office.Interop.Access.Form

      Dim txt As Microsoft.Office.Interop.Access.TextBox

      fom = oAccess.Forms.Item("Form0")

      txt = fom.Controls.Item("Text0")

      txt.SetFocus()

      txt.Text = "TextTest"

    Monday, February 20, 2017 3:25 AM