Back
.
.
Overview | MS Excel |
MS Word 6.0 | MS Word 97 |
WordPerfect | Quattro Pro |
Progman
DDE Example: MS Access
The following example opens the example database NWIND.MDB in MS Access and requests
the available categories. Please note that Microsoft Access must be started before running
this example. This example can also be found in the EXAMPLES directory (ddeacces.bas).
The DDE functions are printed in red bold characters.
10!RE-STORE "examples\ddeacces.bas"
20 ! ***********************************************************************
30 ! * *
40 ! * BASIC DDE Client example for Microsoft Access (English and German) *
50 ! * *
60 ! * Version : 1.0 *
70 ! * Author : Sven Henze, Tech Soft GmbH *
80 ! * Created : 01-Feb-1999 *
90 ! * Updated : 15-Jul-1999 *
100 ! * *
110 ! * Comments: You must start Microsoft Access before you can use this *
120 ! * application. *
130 ! * *
140 ! * Copyright (c) 1999 Tech Soft GmbH. All Rights Reserved. *
150 ! * Email: HTB@TechSoft.de *
160 ! * www.TechSoft.de *
170 ! * *
180 ! ***********************************************************************
190 !
200 ! Description:
210 !
220 ! This example application uses the standard Access example "nwind.mdb"
230 ! in order to request some data from the database.
240 !
250 !
260 IF NOT INMEM("Ddeinit") THEN LOADSUB ALL FROM "htbdde.csb"
270 INTEGER Rs,Ch1,Ch2,A,B,Lang
280 DIM Ret$[512],Topic$[256],Ncomm$[80],Cate$[80],Tablelist$[8192],Reportlist$[8192]
290 !
300 Lf$=CHR$(10)
310 CLEAR SCREEN
320 PRINT "Make sure that Microsoft Access is started !"
330 !
340 INPUT "Select MSAccess Language (1=German, 2=English):",Lang
350 SELECT Lang
360 CASE 1
370 Ncomm$="beispiel\"
380 Cate$="Katalog"
390 CASE 2
400 Ncomm$="example\"
410 Cate$="Catalog"
420 CASE ELSE
430 BEEP
440 PRINT "Wrong language selected. program stopped."
450 STOP
460 END SELECT
470 !
480 Ddeinit(Rs) ! Initialize DDE client
490 IF Rs=0 THEN
500 Ddeconnect(Ch1,"MSAccess","System")! Connect to Excel
510 IF Ch1>0 THEN
520 Ddeexecute(Ch1,"[OpenDatabase "&Ncomm$&"nwind.mdb]",Rs)
530 IF Rs=0 THEN
540 Ddeconnect(Ch2,"MSAccess","nwind")
550 ! request a list of available tables
560 Dderequest(Ch2,"TableList",Tablelist$,Rs)
570 ! request a list of available reports
580 Dderequest(Ch2,"ReportList",Reportlist$,Rs)
590 Showlist(Tablelist$,"Table list of NWIND")
600 DISP "Press <RETURN> to show report list."
610 ENTER KBD
620 Showlist(Reportlist$,"Report list of NWIND")
630 Ddeterminate(Ch2,Rs)
640 DISP "DDE Access example finished."
650 ELSE
660 BEEP
670 PRINT
680 PRINT "Database NWIND.MDB could not be found. Program stopped."
690 STOP
700 END IF
710 Ddeexecute(Ch1,"[CloseDatabase]",Rs)
720 Ddeterminate(Ch1,Rs)
730 ELSE
740 BEEP
750 PRINT
760 PRINT "Connection to Microsoft Access failed."
770 END IF
780 Ddeclean(Rs) ! Clean up ressources
790 END IF
800 END
810 !
820 SUB Showlist(Lst$,Text$)
830 ! shows a list of TAB-separated strings
840 PRINT
850 PRINT Text$
860 PRINT "* ";
870 FOR I=1 TO LEN(Lst$)
880 IF Lst$[I;1]<>CHR$(9) THEN
890 PRINT Lst$[I;1];
900 ELSE
910 PRINT
920 J=J+1
930 PRINT "* ";
940 END IF
950 NEXT I
960 SUBEND