accessing data in word from access database 
Author Message
 accessing data in word from access database

Hi,
   I had crated a table in access database with fields
like jobnumber,Name, address, phone number etc with
jobnumber as the primary key. I want to retrieve the
record in a way that when I will enter the jobnumber in
the field the rest the rest of the record relating to that
jobnumber will be automatically filled.
           Can someone help please.........

Sarbjit Singh



Fri, 20 Feb 2004 21:07:44 GMT  
 accessing data in word from access database
Hi Sarbjit,

Here's a simple example
Assuming this is the situation:
UserForm1
ListBox1 (for Jobnumbers)
txtName (textbox for field Name)
txtAddress (textbox for field Address)
txtPhonenumber (textbox for field Phonenumber)

Database:
c:\temp\db5.mdb
Tabel: TblJob
fieldnames: Jobnumber (long integer/primkey), Name (text), Address (text)
and Phonenumber (text)

'General declaration section
Private ws As DAO.Workspace
Private db As DAO.Database

'Listing of event routines
'----------------------------
Private Sub ListBox1_Change()
    Dim rs      As Recordset
    Dim sSQL    As String

    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase("c:\temp\db5.mdb")
    sSQL = "SELECT * FROM TblJob WHERE Jobnumber=" & Me.ListBox1
    Set rs = db.OpenRecordset(sSQL, dbOpenSnapshot)

    For Each myFld In rs.Fields
        If myFld.Name <> "Jobnumber" Then
            Controls("txt" & myFld.Name).Value = myFld
        End If
    Next
    rs.Close: Set rs = Nothing
End Sub

Private Sub UserForm_Initialize()
    Dim rs As DAO.Recordset
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase("c:\temp\db5.mdb")
    Set rs = db.TableDefs("TblJob").OpenRecordset
    rs.MoveLast
    rs.MoveFirst
    Me.ListBox1.Column = rs.GetRows(rs.RecordCount)
    rs.Close: Set rs = Nothing
End Sub

Private Sub UserForm_Terminate()
On Error Resume Next
If Not rs Is Nothing Then rs.Close: Set rs = Nothing
If Not db Is Nothing Then Set db = Nothing
If Not ws Is Nothing Then ws.Close: Set ws = Nothing
Err.Clear
End Sub

Kind regards,
Perry



Quote:
> Hi,
>    I had crated a table in access database with fields
> like jobnumber,Name, address, phone number etc with
> jobnumber as the primary key. I want to retrieve the
> record in a way that when I will enter the jobnumber in
> the field the rest the rest of the record relating to that
> jobnumber will be automatically filled.
>            Can someone help please.........

> Sarbjit Singh



Sat, 21 Feb 2004 23:36:34 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. merging data from a secured Access database into a Word document

2. sending bookmark data from word 97 to access 97 database

3. VB4: How to let a Data control access a password protected ACCESS database

4. Accessing Data in a text Document and Porting it to an access database

5. Accessing data from a Access 97 database

6. Slow access time when using Data control to Access Database

7. move between Access and Word, back to Access, Close word

8. Importing Word doc into Access database or Oracle database

9. Importing Word doc into Access database or Oracle database

10. Q: Data from Access database without Data Control

11. Accessing Word Style Tags for Database Conversion

12. Saving an Embedded Word Document to an Access Database

 

 
Powered by phpBB® Forum Software