Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

read in data from access

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
macroapa - 29 May 2008 12:29 GMT
Hi, I have an access data base call xyz.mdb which has 1 table called
AutoPostCount

the table consists of 2 field, the first 'DateDone' and the second
called 'CountDone'.

what I want to be able to do is look up the countdone for the
specified date and then increment that figure by 1.

I know how to add a new record to a data base, but not how to read in
a specific bit of data from a record and how to amend that record.

Any help or pointers appreciated.

Thanks.
Doug Robbins - Word MVP - 29 May 2008 12:50 GMT
See the article "Access a database and insert into a Word document the data
that you find there" at:

http://www.word.mvps.org/FAQs/InterDev/GetDataFromDB.htm

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi, I have an access data base call xyz.mdb which has 1 table called
> AutoPostCount
[quoted text clipped - 11 lines]
>
> Thanks.
macroapa - 29 May 2008 13:42 GMT
Thanks for that, that certainly helps, but i'm having problems
connecting to the database.

I have added the 2 reference mentioned under tools-references and my
code is:

   Dim myDatabase As Database
   Dim myActiveRecord As Recordset

   Set myDatabase = OpenDatabase("J:\PrintCount.mdb")

but is debugs on the Set line of code saying '429' ActiveX component
cant create object.

Any idea's where i;m going wrong?  WinXP Professional with OfficeXP

Thanks for the help.
cyberdude - 29 May 2008 14:18 GMT
Hi,

Did you establish the reference from the VB editor?  One line in the
webpage that Doug referred to says:

One final tip: In order for this code to run, you must establish a
reference, in your template, to Microsoft DAO 3.51 Object Library and
Microsoft Datasource Interfaces. To do this, open the VB editor and
choose References on the Tools menu.

Hope this helps.

Mike

> Thanks for that, that certainly helps, but i'm having problems
> connecting to the database.
[quoted text clipped - 13 lines]
>
> Thanks for the help.
macroapa - 29 May 2008 15:00 GMT
Yep sure did:

> > I have added the 2 reference mentioned under tools-references and my
> > code is:
Doug Robbins - Word MVP - 30 May 2008 01:42 GMT
Have you tried re-booting

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Yep sure did:
>
>> > I have added the 2 reference mentioned under tools-references and my
>> > code is:
alborg - 30 May 2008 06:22 GMT
(sorry if the post is repeated twice- I got an error on the last post)

Hi macroapa:

You might have run into the linking issue that took me quite a long time to
figure out. I have a program that links up to a table located in an external
mdb container. The code that Doug posted is correct, but what you have to do
is to link TWICE to the mdb, once when you open the template and then when
you open the new doc file. So go to your VB editor pane and:

1) Go to YourProjectName-> Microsoft Word Objects-> ThisDocument and place
the following code-

Option Explicit

Private Sub Document_New()
On Error Resume Next
Dim accessword As AccessObject                                
'Word.Application
Dim Accesswasnotrunning As Boolean   ' Flag for final release.
Dim wdWindowStateMaximize As Long
   wdWindowStateMaximize = 0
On Error Resume Next
conDBpath2 = "J:\PrintCount.mdb"
Set accessword = GetObject("J:\PrintCount.mdb", "Access.Application")
   accessword.Application.Visible = True
   If Err.Number <> 0 Then    'test to see if an error occurred
Set accessword = CreateObject("Access.Application")
   End If
   If Accesswasnotrunning = True Then
       accessword.Application.Quit
   End If
       With accessword
       .WindowState = wdWindowStateMinimize
       End With
Set accessword = Nothing
On Error GoTo ErrorHandler
Load frmSplashscreen
frmSplashscreen.Show
ErrorHandlerEXit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerEXit
End Sub

2) In your first popup form, place the following code-

Private Sub UserForm_Initialize()
On Error Resume Next
Application.DisplayAlerts = wdAlertsNone
Dim accessword As Object
Dim Accesswasnotrunning As Boolean   ' Flag for final release.
Dim wdWindowStateMaximize As Long
   wdWindowStateMaximize = 0
Set accessword = GetObject(, "Access.Application")
   If Err.Number <> 0 Then    'test to see if an error occurred
       Set accessword = CreateObject("Access.Application")
   End If
Set accessword = GetObject("J:\PrintCount.mdb", "Access.Application")
   If Err.Number <> 0 Then Accesswasnotrunning = True
       Set accessword = CreateObject("J:\PrintCount.mdb",
"Access.Application")
   If Accesswasnotrunning = True Then
       accessword.Application.Quit
   End If
   accessword.Application.Visible = False
   If Err.Number <> 0 Then    'test to see if an error occurred
       Set accessword = CreateObject("Access.Application")
   End If
       With accessword
       End With
Set accessword = Nothing
Proc_Exit:
Exit Sub
Proc_Error:
Call EMRError("WORD EMR Project.dot/" & Me.Name & ":
CommandButton11_Click()", Err.Number, Err.Source, Err.Description)
Resume Proc_Exit
End Sub

So, if you login twice, it'll work.

Regards,
Al

> Thanks for that, that certainly helps, but i'm having problems
> connecting to the database.
[quoted text clipped - 13 lines]
>
> Thanks for the help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.