Code:'here is some code to open a db and put your field 'in a text box '******************************* 'change yourdatabasename to the name of your database 'change yourtablename to the name of the table in your databas 'change yourfieldname to the name of the field in your database '******************************** 'add a data control to a form Data1 'add a textbox to the form Text1 'set the Datasource Property of Text1 to Data1 'copy and paste this code after changing the names above ' 'run the app. Option Explicit 'open database and set database and recordset Public db As Database, rs As Recordset Public cTblName As String Public cdbName As String Public Sub OpenDB() Dim AppPath$ If Right(App.Path, 1) <> "\" Then _ AppPath = App.Path & "\" _ Else AppPath = App.Path cdbName = AppPath & "YourDatabaseName.mdb" cTblName = "YourTableName" Data1.DatabaseName = cdbName Data1.RecordSource = cTblName Text1.DataField = "yourfieldname" Data1.Refresh End Sub Private Sub Form_Load() ' Call OpenDB ' Set db = Workspaces(0).OpenDatabase(cdbName) Set rs = db.OpenRecordset(cTblName) End Sub




Reply With Quote