Return to the Word form and double-click txtPhone. MsgBox Err.Number & ": " & Err.Description, _Įnd Sub Figure C Reference the ADO library MsgBox "You inserted " & lngSuccess & " record", _ĭoc.FormFields("txtCompanyName").TextInput.Clearĭoc.FormFields("txtPhone").TextInput.Clear StrPath = "C:Program FilesMicrosoft Office11Office11SamplesNorthwind.mdb" 'Substitute path and connection string with DSN if available.
StrPhone = Chr(39) & doc.FormFields("txtPhone").Result & Chr(39)īytContinue = MsgBox("Do you want to insert this record?", vbYesNo, "Add Record") StrCompanyName = Chr(39) & doc.FormFields("txtCompanyName").Result & Chr(39) (It isn't enough to highlight the library item you must check it.) The Word Object and VBA libraries should already be referenced.
Be sure to update the path if yours differs from the example's path. Open the Visual Basic Editor (VBE) by pressing Alt+F11.Once you have a form to fill out, you need the VBA function that transfers input values to an Access database. (The txt tag identifies the field as a text field.) It isn't necessary to name your Word fields this way, but doing so makes it easier to match Word fields to Access fields. Notice that the Word field names are similar to the Access field names, CompanyName and Phone. Check the Show Developer tab in the Ribbon option, and click OK.Click the Office button and then click Word Options (in the bottom right corner).In Word 2007, you may need to add the Developer tab as follows: Repeat step 4 and identify the second control as txtPhone.įigure B Identify both text form controls.
Here is how to use a Word form to collect data from users and then transfer that data to an Access table. In some cases, Access might not be installed on every users system, or you might prefer users not have access to your database. Although Access forms are powerful interface objects, your users might not be familiar with them.