home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmDDE
- Caption = "DDE with Access 2.0"
- ClientHeight = 4770
- ClientLeft = 60
- ClientTop = 1380
- ClientWidth = 7365
- Height = 5175
- Icon = "frmdde.frx":0000
- Left = 0
- LinkTopic = "Form1"
- ScaleHeight = 4770
- ScaleWidth = 7365
- Top = 1035
- Width = 7485
- Begin VB.CommandButton cmd
- Caption = "E&xecute"
- Height = 375
- Index = 1
- Left = 5940
- TabIndex = 12
- Top = 540
- Width = 1230
- End
- Begin VB.CommandButton cmd
- Caption = "&Request"
- Height = 375
- Index = 0
- Left = 5940
- TabIndex = 10
- Top = 90
- Width = 1230
- End
- Begin VB.ComboBox cbo
- Height = 315
- Index = 2
- Left = 135
- TabIndex = 7
- Text = "cbo"
- Top = 2205
- Width = 7000
- End
- Begin VB.ComboBox cbo
- Height = 315
- Index = 1
- Left = 135
- TabIndex = 5
- Text = "cbo"
- Top = 1620
- Width = 7000
- End
- Begin VB.ComboBox cbo
- Height = 315
- Index = 0
- Left = 135
- TabIndex = 3
- Text = "cbo"
- Top = 1035
- Width = 7000
- End
- Begin VB.TextBox txtResult
- Height = 1860
- Left = 135
- MultiLine = -1 'True
- ScrollBars = 3 'Both
- TabIndex = 9
- Top = 2790
- Width = 7005
- End
- Begin VB.TextBox txtDatabase
- Height = 285
- Left = 135
- TabIndex = 1
- Text = "c:\vb\biblio.mdb"
- Top = 405
- Width = 5685
- End
- Begin VB.Label DDESource
- Caption = "DDESource"
- Height = 330
- Left = 4725
- TabIndex = 11
- Top = 45
- Visible = 0 'False
- Width = 1050
- End
- Begin VB.Label lbl
- BackStyle = 0 'Transparent
- Caption = "Res&ult:"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 195
- Index = 4
- Left = 135
- TabIndex = 8
- Top = 2565
- Width = 2400
- End
- Begin VB.Label lbl
- BackStyle = 0 'Transparent
- Caption = "&Execute:"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 195
- Index = 3
- Left = 135
- TabIndex = 6
- Top = 1980
- Width = 2400
- End
- Begin VB.Label lbl
- BackStyle = 0 'Transparent
- Caption = "&Item:"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 195
- Index = 2
- Left = 135
- TabIndex = 4
- Top = 1395
- Width = 2400
- End
- Begin VB.Label lbl
- BackStyle = 0 'Transparent
- Caption = "&Topic:"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 195
- Index = 1
- Left = 135
- TabIndex = 2
- Top = 810
- Width = 2400
- End
- Begin VB.Label lbl
- BackStyle = 0 'Transparent
- Caption = "&Database Location:"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 195
- Index = 0
- Left = 135
- TabIndex = 0
- Top = 180
- Width = 2400
- End
- Attribute VB_Name = "frmDDE"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- '*************************************************************
- ' FRMDDE.FRM: User interface for DDE with Access 2.0.
- '*************************************************************
- Option Explicit
- '*************************************************************
- ' This is the DDE topic name that is used by all DDE connects
- ' in this demonstration program.
- '*************************************************************
- Const DDE_APPLICATION = "MSAccess"
- '*************************************************************
- ' These are the indexes of the cbo control array.
- '*************************************************************
- Const DDE_TOPIC = 0 'cbo(0)
- Const DDE_ITEM = 1 'cbo(1)
- Const DDE_EXECUTE = 2 'cbo(2)
- '*************************************************************
- ' Arbitrary constants which are used to populate the cbo(1)
- ' list with valid commands.
- '*************************************************************
- Const ITEMS_SYSTEM = 0
- Const ITEMS_LISTS = 1
- Const ITEMS_DATA = 2
- '*************************************************************
- ' This variable stores the path to BIBLIO.MDB file.
- '*************************************************************
- Private DatabaseName As String
- '*************************************************************
- ' When cbo(0) loses its focus, cbo(1) needs to be updated
- ' with valid DDE commands.
- '*************************************************************
- Private Sub cbo_LostFocus(Index As Integer)
- Select Case Index
- Case DDE_TOPIC
- If InStr(cbo(DDE_TOPIC), "System") Then
- LoadItems ITEMS_SYSTEM
- ElseIf InStr(cbo(DDE_TOPIC), ";TABLE") Then
- LoadItems ITEMS_DATA
- ElseIf InStr(cbo(DDE_TOPIC), ";QUERY") Then
- LoadItems ITEMS_DATA
- ElseIf InStr(cbo(DDE_TOPIC), ";SQL") Then
- LoadItems ITEMS_DATA
- Else
- LoadItems ITEMS_LISTS
- End If
- Case DDE_ITEM
- Case DDE_EXECUTE
- End Select
- End Sub
- '*************************************************************
- ' Either request data, or execute a command.
- '*************************************************************
- Private Sub cmd_Click(Index As Integer)
- Select Case Index
- '*****************************************************
- ' Request Data.
- '*****************************************************
- Case 0
- '*************************************************
- ' Get the data from Access and close the link.
- '*************************************************
- DDERequest DDESource, DDE_APPLICATION, _
- (cbo(DDE_TOPIC).Text), (cbo(DDE_ITEM).Text)
- '*************************************************
- ' If the data returned doesn't contain a line
- ' feed, then replace tabs with carriage returns.
- '*************************************************
- If InStr(DDESource, Chr$(10)) = 0 Then
- txtResult = Replace(DDESource, Chr$(9), _
- Chr$(13) & Chr$(10))
- '*************************************************
- ' Otherwise display the data as is was received.
- '*************************************************
- Else
- txtResult = DDESource
- End If
- '*****************************************************
- ' Execute a Command.
- '*****************************************************
- Case 1
- txtResult = ""
- DDEExecute DDESource, DDE_APPLICATION, _
- (cbo(DDE_EXECUTE).Text)
- End Select
- End Sub
- '*************************************************************
- ' Load cbo(0) with some valid topics for Access.
- '*************************************************************
- Private Sub LoadTopics()
- With cbo(DDE_TOPIC)
- .Clear
- .AddItem "System"
- .AddItem DatabaseName
- .AddItem DatabaseName & ";TABLE Authors"
- .AddItem DatabaseName & ";QUERY [By State]"
- .AddItem DatabaseName & ";SQL Select * From Authors"
- .ListIndex = 0
- End With
- End Sub
- '*************************************************************
- ' Load cbo(1) with some valid items for Access, based on a
- ' specific type of topic.
- '*************************************************************
- Private Sub LoadItems(TypeOfTopic As Integer)
- With cbo(DDE_ITEM)
- .Clear
- Select Case TypeOfTopic
- Case ITEMS_SYSTEM
- .AddItem "Status"
- .AddItem "Topics"
- .AddItem "SysItems"
- .AddItem "Formats"
- Case ITEMS_LISTS
- .AddItem "TableList"
- .AddItem "QueryList"
- .AddItem "FormList"
- .AddItem "ReportList"
- .AddItem "MacroList"
- .AddItem "ModuleList"
- Case ITEMS_DATA
- .AddItem "All"
- .AddItem "Data"
- .AddItem "FieldNames"
- .AddItem "FieldNames;T"
- .AddItem "FieldCount"
- .AddItem "NextRow"
- .AddItem "PrevRow"
- .AddItem "LastRow"
- .AddItem "FirstRow"
- .AddItem "SQLText"
- .AddItem "SQLText;5"
- Case Else
- LoadItems ITEMS_SYSTEM
- End Select
- .ListIndex = 0
- End With
- End Sub
- '*************************************************************
- ' Loads cbo(2) with some valid Access LinkExecute commands.
- '*************************************************************
- Private Sub LoadExecutes()
- With cbo(DDE_EXECUTE)
- .Clear
- .AddItem "[OpenDatabase " & DatabaseName & "]"
- .AddItem "[CloseDatabase]"
- .ListIndex = 0
- End With
- End Sub
- '*************************************************************
- ' Prepares the form for use. This function is also called
- ' by txtDatabase_LostFocus to refresh the form.
- '*************************************************************
- Private Sub Form_Load()
- #If Win32 Then
- MsgBox "This sample is for Win16 only!", vbCritical
- End
- #End If
- DatabaseName = txtDatabase
- LoadTopics
- LoadItems ITEMS_SYSTEM
- LoadExecutes
- txtResult = ""
- DDESource = ""
- End Sub
- '*************************************************************
- ' Resizes the controls to the size of the form. This function
- ' is not foolproof, so don't try to break it.
- '*************************************************************
- Private Sub Form_Resize()
- Static Border%
- Dim i%
- '*********************************************************
- ' If the form is minimized, then break out.
- '*********************************************************
- If WindowState = 1 Then Exit Sub
- '*********************************************************
- ' Load the border variable, once.
- '*********************************************************
- If Not Border Then Border = txtDatabase.Left * 2
- '*********************************************************
- ' Adjust the combo boxes and command buttons.
- '*********************************************************
- For i = 0 To 2
- cbo(i).Width = ScaleWidth - Border
- If i < 2 Then cmd(i).Left = cbo(i).Width + _
- cbo(i).Left - cmd(i).Width
- Next
- '*********************************************************
- ' Adjust the text boxes.
- '*********************************************************
- txtDatabase.Width = cmd(0).Left - (txtDatabase.Left * 2)
- txtResult.Move txtResult.Left, _
- txtResult.Top, ScaleWidth - Border, _
- ScaleHeight - txtResult.Top - (Border / 2)
- End Sub
- '*************************************************************
- ' Updates the database variable and reloads the combo boxes
- ' to reflect any changes.
- '*************************************************************
- Private Sub txtDatabase_LostFocus()
- DatabaseName = txtDatabase
- Form_Load
- End Sub
-