home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Microsoft Plateform / Visual Basic 5.0 / Msvb50.ace / msvb50 / MSVB50 / VB / SAMPLES / VISDATA / VISDATA.BAS < prev    next >
Encoding:
BASIC Source File  |  1997-01-23  |  70.4 KB  |  2,262 lines

  1. Attribute VB_Name = "modVisData"
  2. '------------------------------------------------------------
  3. ' VISDATA.BAS
  4. ' support functions for the Visual Data sample application
  5. '
  6. ' General Information: This app is intended to demonstrate
  7. '   and exercise all of the functionality available in the
  8. '   DAO (Data Access Objects) in Visual Basic 5.0.
  9. '
  10. '------------------------------------------------------------
  11.  
  12. Option Explicit
  13. '>>>>>>>>>>>>>>>>>>>>>>>>
  14. Const MSG1 = "Execute Commit or Rollback First."
  15. Const MSG2 = "Closing Recordsets"
  16. Const MSG3 = "Table already exists, delete it?"
  17. Const MSG4 = "Enter New Table Name:"
  18. Const MSG5 = "Ready"
  19. Const MSG6 = ", please wait..."
  20. Const MSG7 = "Refreshing Table List"
  21. Const MSG8 = "Number: "
  22. Const MSG9 = "Display the Data Access Errors Collection?"
  23. Const MSG10 = "Can't Open a Table Object on an Attached Table, Use Dynaset?"
  24. Const MSG11 = "Opening Attached Table as Dynaset"
  25. Const MSG12 = "Opening Attached Table as Snapshot"
  26. Const MSG13 = "Opening Full Table"
  27. Const MSG14 = "Opening Single Table Dynaset"
  28. Const MSG15 = "Opening Single Table Snapshot"
  29. Const MSG16 = "Opening PassThru Snapshot"
  30. Const MSG17 = "Is this a SQLPassThrough Query?"
  31. Const MSG18 = "Enter Connect property value:"
  32. Const MSG19 = "Can't Open a Table Object from a QueryDef, Use Dynaset?"
  33. Const MSG20 = "Opening Query Snapshot"
  34. Const MSG21 = "Opening Query Dynaset"
  35. Const MSG22 = "SQL Statement"
  36. Const MSG23 = "Execute "
  37. Const MSG24 = " Query?"
  38. Const MSG25 = "Executing Query"
  39. Const MSG26 = "  [Not Updatable]"
  40. Const MSG27 = "Table already exists, Delete it?"
  41. Const MSG28 = "QueryDef already exists, Delete it?"
  42. Const MSG29 = "Enter Value for Parameter:"
  43. Const MSG30 = "There are no current data access errors!"
  44. Const MSG31 = "Can't show Errors at this time!"
  45. Const MSG32 = "Data has been changed, Commit it?"
  46. Const MSG33 = "RollBack All changes?"
  47. Const MSG34 = "Can't Close with Transactions Pending!"
  48. Const MSG35 = "You must Close First!"
  49. Const MSG36 = "Open Microsoft Access Database"
  50. Const MSG37 = "Open Dbase Database"
  51. Const MSG38 = "Open FoxPro Database"
  52. Const MSG39 = "Open Paradox Database"
  53. Const MSG40 = "Open Excel File"
  54. Const MSG41 = "Open Btrieve Database"
  55. Const MSG42 = "Open Text Database"
  56. Const MSG43 = "Opening Database"
  57. Const MSG44 = "NOTE: Use of Attached Tables is the Recommended Method"
  58. Const MSG45 = "Repairing "
  59. Const MSG46 = "Attempt to Repair it?"
  60. Const MSG47 = "Enter Directory Name for New ISAM Database:"
  61. Const MSG48 = "Select Microsoft Access Database to Compact"
  62. Const MSG49 = "Microsoft Access MDBs (*.mdb)|*.mdb"
  63. Const MSG50 = "|All Files (*.*)|*.*"
  64. Const MSG51 = "Select Microsoft Access Database to Compact to"
  65. Const MSG52 = "Encrypt Compacted Database?"
  66. Const MSG53 = "Compacting "
  67. Const MSG54 = "Open Newly Compacted Database?"
  68. Const MSG55 = "Select Microsoft Access Database to Create"
  69. Const MSG56 = "Exporting Table: "
  70. Const MSG57 = "Export "
  71. Const MSG58 = "in "
  72. Const MSG59 = "Creating Indexes:"
  73. Const MSG60 = "Successfully Exported:"
  74. Const MSG61 = "Successfully Exported SQL Statement."
  75. Const MSG62 = "Table already exists - overwrite?"
  76. Const MSG63 = "Importing Table: "
  77. Const MSG64 = "Successfully Imported:"
  78. Const MSG65 = "Invalid Directory Name!"
  79. '>>>>>>>>>>>>>>>>>>>>>>>>
  80.  
  81.  
  82. 'api declarations
  83. Declare Function OSGetPrivateProfileString% Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal ReturnString$, ByVal NumBytes As Integer, ByVal FileName$)
  84. Declare Function OSWritePrivateProfileString% Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal FileName$)
  85. Declare Function OSWinHelp% Lib "user32" Alias "WinHelpA" (ByVal hwnd&, ByVal HelpFile$, ByVal wCommand%, dwData As Any)
  86. Declare Function SQLAllocEnv% Lib "ODBC32.DLL" (env&)
  87. Declare Function SQLDataSources% Lib "ODBC32.DLL" (ByVal henv&, ByVal fdir%, ByVal szDSN$, ByVal cbDSNMax%, pcbDSN%, ByVal szDesc$, ByVal cbDescMax%, pcbDesc%)
  88. Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
  89. Declare Function GetDesktopWindow Lib "user32" () As Long
  90.  
  91. 'global object variables
  92. Global gVDClass      As New VisDataClass
  93. Global gnodDBNode    As Node        'current database node in treeview
  94. Global gnodDBNode2   As Node        'backup of current database node in treeview
  95. Global gwsMainWS     As Workspace   'main workspace object
  96. Global gdbCurrentDB  As Database    'main database object
  97. Global gbDBOpenFlag  As Integer     'flag to know if a db is open
  98. Global gPropObject   As Object      'object to show properties on
  99. Global gDataCtlObj   As Object      'global data control object
  100. Global gtdfTableDef  As TableDef    'global tabledef used by frmTblStruct
  101. Global gnFormType    As Integer     'form type chosen on main form
  102.                                     '0 = data control
  103.                                     '1 = no data control
  104.                                     '2 = grid control
  105. Global gnRSType      As Integer     'recordset type chosen on main form
  106.                                     '0 = table
  107.                                     '1 = dynaset
  108.                                     '2 = snapshot
  109.  
  110. 'global database variables
  111. Global gsDataType       As String   'data backend = connect string
  112.                                     'for everything accept Access
  113. Global gsDBName         As String   'current database name
  114. Global gsODBCDatasource As String   'global odbc values
  115. Global gsODBCDatabase   As String   '       "
  116. Global gsODBCUserName   As String   '       "
  117. Global gsODBCPassword   As String   '       "
  118. Global gsODBCDriver     As String   '       "
  119. Global gsODBCServer     As String   '       "
  120. Global gsTblName        As String   '
  121. Global glQueryTimeout   As Long     '
  122. Global glLoginTimeout   As Long     '
  123. Global gsTableDynaFilter As String  '
  124. Global gnReadOnly       As Integer  'database readonly flag
  125.  
  126. 'other global vars
  127. Global gsZoomData       As String   'pass info to the zoom form
  128.  
  129. 'multi user variables
  130. Global gnMURetryCnt     As Integer
  131. Global gnMUDelay        As Integer
  132. Global gnMULocking      As Integer  'flag for pessimistic or optimistic locking
  133.  
  134. 'global find values used to pass info between
  135. 'the dynaset form and find dialog
  136. Global gbFindFailed     As Boolean
  137. Global gsFindExpr       As String
  138. Global gsFindOp         As String
  139. Global gsFindField      As String
  140. Global gnFindType       As Integer
  141. Global gbFromTableView  As Boolean
  142.  
  143. 'global seek values used to pass info between
  144. 'the table form and find dialog
  145. Global gsSeekOperator   As String
  146. Global gsSeekValue      As String
  147.  
  148. 'global flags
  149. Global gbDBChanged      As Boolean   '
  150. Global gbTransPending   As Boolean   'used for transaction management
  151. Global gbFromSQL        As Boolean   'source of sql statement was SQL form
  152. Global gbAddTableFlag   As Boolean   'new or design designator
  153. Global gbSettingDataCtl As Boolean   'used to reset data control props
  154.  
  155. 'global vars used in the Import Export Code
  156. Global gnDataType As Integer
  157. Global gImpDB As Database
  158. Global gExpDB As Database
  159. Global gExpTable As String
  160.  
  161. 'data backend types used as the connect string
  162. Global Const gsMSACCESS = "Microsoft Access"
  163. Global Const gsDBASEIII = "Dbase III;"
  164. Global Const gsDBASEIV = "Dbase IV;"
  165. Global Const gsDBASE5 = "Dbase 5.0;"
  166. Global Const gsFOXPRO20 = "FoxPro 2.0;"
  167. Global Const gsFOXPRO25 = "FoxPro 2.5;"
  168. Global Const gsFOXPRO26 = "FoxPro 2.6;"
  169. Global Const gsFOXPRO30 = "FoxPro 3.0;"
  170. Global Const gsPARADOX3X = "Paradox 3.X;"
  171. Global Const gsPARADOX4X = "Paradox 4.X;"
  172. Global Const gsPARADOX5X = "Paradox 5.X;"
  173. Global Const gsBTRIEVE = "Btrieve;"
  174. Global Const gsEXCEL30 = "Excel 3.0;"
  175. Global Const gsEXCEL40 = "Excel 4.0;"
  176. Global Const gsEXCEL50 = "Excel 5.0;"
  177. Global Const gsTEXTFILES = "Text;"
  178. Global Const gsSQLDB = "ODBC;"
  179.  
  180. 'import/export data types
  181. Global Const gnDT_NONE = -1
  182. Global Const gnDT_MSACCESS = 0
  183. Global Const gnDT_DBASEIV = 1
  184. Global Const gnDT_DBASEIII = 2
  185. Global Const gnDT_FOXPRO26 = 3
  186. Global Const gnDT_FOXPRO25 = 4
  187. Global Const gnDT_FOXPRO20 = 5
  188. Global Const gnDT_PARADOX4X = 6
  189. Global Const gnDT_PARADOX3X = 7
  190. Global Const gnDT_BTRIEVE = 8
  191. Global Const gnDT_EXCEL50 = 9
  192. Global Const gnDT_EXCEL40 = 10
  193. Global Const gnDT_EXCEL30 = 11
  194. Global Const gnDT_TEXTFILE = 12
  195. Global Const gnDT_SQLDB = 13
  196.  
  197. 'global constants
  198. Global Const gsDEFAULT_DRIVER = "SQL Server"  'used for registerdatabase
  199. Global Const gnEOF_ERR = 626                  '
  200. Global Const gnFTBLS = 0                      '
  201. Global Const gnFFLDS = 1                      '
  202. Global Const gnFINDX = 2                      '
  203. Global Const gnMAX_GRID_ROWS = 31999          '
  204. Global Const gnMAX_MEMO_SIZE = 20000          '
  205. Global Const gnGETCHUNK_CUTOFF = 50           '
  206.  
  207. Global Const gnFORM_DATACTL = 0               '
  208. Global Const gnFORM_NODATACTL = 1             '
  209. Global Const gnFORM_DATAGRID = 2              '
  210.  
  211. Global Const gnRS_TABLE = vbRSTypeTable
  212. Global Const gnRS_DYNASET = vbRSTypeDynaset
  213. Global Const gnRS_SNAPSHOT = vbRSTypeSnapShot
  214. Global Const gnRS_PASSTHRU = 8
  215.  
  216. Global Const gnCTLARRAYHEIGHT = 340&          '
  217. Global Const gnSCREEN = 0                     'used to center forms on screen
  218. Global Const gnMDIFORM = 1                    'used to center forms on frmMDI
  219.  
  220. Global Const TABLE_STR = "Table"
  221. Global Const ATTACHED_STR = "Attached"
  222. Global Const QUERY_STR = "Query"
  223. Global Const FIELD_STR = "Field"
  224. Global Const FIELDS_STR = "Fields"
  225. Global Const INDEX_STR = "Index"
  226. Global Const INDEXES_STR = "Indexes"
  227. Global Const PROPERTY_STR = "Property"
  228. Global Const PROPERTIES_STR = "Properties"
  229.  
  230. Global Const APP_CATEGORY = "Microsoft Visual Basic AddIns"
  231.  
  232. Sub Main()
  233.   frmMDI.Show
  234. End Sub
  235.  
  236.  
  237. '------------------------------------------------------------
  238. 'this function returns the type of querydef
  239. 'for the item selected in the querydefs
  240. 'list on the frmTables form
  241. '------------------------------------------------------------
  242. Function ActionQueryType(qdf As QueryDef) As String
  243.   
  244.   'check to see if it is an action query
  245.   If (qdf.Type And dbQAction) = 0 Then
  246.     ActionQueryType = vbNullString
  247.     Exit Function
  248.   End If
  249.   
  250.   'must be an action query type
  251.   Select Case qdf.Type
  252.     Case dbQCrosstab
  253.       ActionQueryType = "Cross Tab"
  254.     Case dbQDelete
  255.       ActionQueryType = "Delete"
  256.     Case dbQUpdate
  257.       ActionQueryType = "Update"
  258.     Case dbQAppend
  259.       ActionQueryType = "Append"
  260.     Case dbQMakeTable
  261.       ActionQueryType = "Make Table"
  262.     Case dbQDDL
  263.       ActionQueryType = "DDL"
  264.     Case dbQSQLPassThrough
  265.       ActionQueryType = "SQLPassThrough"
  266.     Case dbQSetOperation
  267.       ActionQueryType = "Set Operation"
  268.     Case dbQSPTBulk
  269.       ActionQueryType = "SPT Bulk"
  270.     Case Else
  271.       ActionQueryType = vbNullString
  272.   End Select
  273.  
  274. End Function
  275.  
  276. '------------------------------------------------------------
  277. 'this functions adds [] to object names that might need
  278. 'them because they have spaces in them
  279. '------------------------------------------------------------
  280. Function AddBrackets(rObjName As String) As String
  281.   'add brackets to object names w/ spaces in them
  282.   If InStr(rObjName, " ") > 0 And Mid(rObjName, 1, 1) <> "[" Then
  283.     AddBrackets = "[" & rObjName & "]"
  284.   Else
  285.     AddBrackets = rObjName
  286.   End If
  287. End Function
  288.  
  289. '------------------------------------------------------------
  290. 'this function checks to see if a transaction is pending
  291. 'and displays a message is one is
  292. '------------------------------------------------------------
  293. Function CheckTransPending(MSG As String) As Integer
  294.  
  295.   If gbTransPending Then
  296.     MsgBox MSG & vbCrLf & MSG1, 48
  297.     CheckTransPending = True
  298.   Else
  299.     CheckTransPending = False
  300.   End If
  301.  
  302. End Function
  303.  
  304. '------------------------------------------------------------
  305. 'clear out the data fields on the table and dynasnap forms
  306. '------------------------------------------------------------
  307. Sub ClearDataFields(frm As Form, nCnt As Integer)
  308.   Dim i As Integer
  309.  
  310.   'clear out the fields on the main form
  311.   For i = 0 To nCnt - 1
  312.     frm.txtFieldData(i).Text = vbNullString
  313.   Next
  314. End Sub
  315.  
  316. '------------------------------------------------------------
  317. 'this sub closes all frmDynaSnap, frmTableObj and frmDataGrid
  318. 'forms by looking for forms with a Tag set to "Recordset"
  319. '------------------------------------------------------------
  320. Sub CloseAllRecordsets()
  321.   Dim i As Integer
  322.  
  323.   MsgBar MSG2, True
  324.   While i < Forms.Count
  325.     If Forms(i).Tag = "Recordset" Then
  326.       Unload Forms(i)
  327.     Else
  328.       i = i + 1
  329.     End If
  330.   Wend
  331.   MsgBar vbNullString, False
  332.  
  333. End Sub
  334.  
  335. '------------------------------------------------------------
  336. 'this function copies data from one table to another
  337. 'from the frmCopyStruct form
  338. 'It demonstrates the use of transactions to speed up this
  339. 'type of operation
  340. '------------------------------------------------------------
  341. Function CopyData(rFromDB As Database, rToDB As Database, rFromName As String, rToName As String) As Integer
  342.   On Error GoTo CopyErr
  343.  
  344.   Dim recRecordset1 As Recordset, recRecordset2 As Recordset
  345.   Dim i As Integer
  346.   Dim nRC As Integer
  347.   Dim fld As Field
  348.  
  349.   'open both recordsets
  350.   Set recRecordset1 = rFromDB.OpenRecordset(rFromName)
  351.   Set recRecordset2 = rToDB.OpenRecordset(rToName)
  352.   gwsMainWS.BeginTrans
  353.   While recRecordset1.EOF = False
  354.     recRecordset2.AddNew
  355.     'this loop copies the data from each field to
  356.     'the new table
  357. '    For Each fld In recRecordset1.Fields
  358.     For i = 0 To recRecordset1.Fields.Count - 1
  359.       Set fld = recRecordset1.Fields(i)
  360.       recRecordset2(fld.Name).Value = fld.Value
  361.     Next
  362.     recRecordset2.Update
  363.     recRecordset1.MoveNext
  364.     nRC = nRC + 1
  365.     'this test will commit transactions every 1000 records
  366.     If nRC = 1000 Then
  367.       gwsMainWS.CommitTrans
  368.       gwsMainWS.BeginTrans
  369.       nRC = 0
  370.     End If
  371.   Wend
  372.   gwsMainWS.CommitTrans
  373.  
  374.   CopyData = True
  375.   Exit Function
  376.  
  377. CopyErr:
  378.   gwsMainWS.Rollback
  379.   ShowError
  380.   CopyData = False
  381. End Function
  382.  
  383. '------------------------------------------------------------
  384. 'this function copies the structure of one table to
  385. 'a new table in the same or different database
  386. '------------------------------------------------------------
  387. Function CopyStruct(vFromDB As Database, vToDB As Database, vFromName As String, vToName As String, bCreateIndex As Integer) As Integer
  388.   On Error GoTo CSErr
  389.  
  390.   Dim i As Integer
  391.   Dim tblTableDefObj As TableDef
  392.   Dim fldFieldObj As Field
  393.   Dim indIndexObj As Index
  394.   Dim tdf As TableDef
  395.   Dim fld As Field
  396.   Dim idx As Index
  397.   
  398.   'search to see if table exists
  399. NameSearch:
  400. '  For Each tdf In vToDB.Tabledefs
  401.   For i = 0 To vToDB.TableDefs.Count - 1
  402.     Set tdf = vToDB.TableDefs(i)
  403.     If UCase(tdf.Name) = UCase(vToName) Then
  404.       If MsgBox(MSG3, 4) = vbYes Then
  405.          vToDB.TableDefs.Delete tdf.Name
  406.       Else
  407.          vToName = InputBox(MSG4)
  408.          If Len(vToName) = 0 Then
  409.            Exit Function
  410.          Else
  411.            GoTo NameSearch
  412.          End If
  413.       End If
  414.       Exit For
  415.     End If
  416.   Next
  417.   
  418.   Set tblTableDefObj = gdbCurrentDB.CreateTableDef()
  419.     
  420.   'strip off owner if needed
  421.   tblTableDefObj.Name = StripOwner(vToName)
  422.  
  423.   'create the fields
  424. '  For Each fld In vFromDB.Tabledefs(vFromName).Fields
  425.   For i = 0 To vFromDB.TableDefs(vFromName).Fields.Count - 1
  426.     Set fld = vFromDB.TableDefs(vFromName).Fields(i)
  427.     Set fldFieldObj = vFromDB.TableDefs(vFromName).CreateField(fld.Name, fld.Type, fld.Size)
  428.     tblTableDefObj.Fields.Append fldFieldObj
  429.   Next
  430.  
  431.   'create the indexes
  432.   If bCreateIndex <> False Then
  433. '    For Each idx In vFromDB.Tabledefs(vFromName).Indexes
  434.     For i = 0 To vFromDB.TableDefs(vFromName).Indexes.Count - 1
  435.       Set idx = vFromDB.TableDefs(vFromName).Indexes(i)
  436.       Set indIndexObj = vFromDB.TableDefs(vFromName).CreateIndex(idx.Name)
  437.       With indIndexObj
  438.         indIndexObj.Fields = idx.Fields
  439.         indIndexObj.Unique = idx.Unique
  440.         If gsDataType <> gsSQLDB Then
  441.           indIndexObj.Primary = idx.Primary
  442.         End If
  443.       End With
  444.       tblTableDefObj.Indexes.Append indIndexObj
  445.     Next
  446.   End If
  447.  
  448.   'append the new table
  449.   vToDB.TableDefs.Append tblTableDefObj
  450.  
  451.   CopyStruct = True
  452.   Exit Function
  453.  
  454. CSErr:
  455.   ShowError
  456.   CopyStruct = False
  457. End Function
  458.  
  459. '------------------------------------------------------------
  460. 'this function fills a list or combo box with the
  461. 'tables (and querydefs) from the Tables form
  462. 'ItemData is set to 0 for a tabledef and 1 for a querydef
  463. '------------------------------------------------------------
  464. Sub GetTableList(rctl As Control, rbIncludeQDFs As Integer, rbIncludeSys As Integer, rbStripConnect As Integer)
  465.   On Error GoTo FTLErr
  466.   
  467.   Dim i As Integer
  468.   Dim sTmp As String
  469.   Dim tbl As TableDef
  470.   Dim qdf As QueryDef
  471.   
  472.   'add the tabledefs
  473.   For Each tbl In gdbCurrentDB.TableDefs
  474.     sTmp = tbl.Name
  475.     If rbIncludeSys Then
  476.       rctl.AddItem sTmp
  477.       rctl.ItemData(rctl.NewIndex) = 0
  478.     Else
  479.       If (gdbCurrentDB.TableDefs(sTmp).Attributes And dbSystemObject) = 0 Then
  480.         rctl.AddItem sTmp
  481.         rctl.ItemData(rctl.NewIndex) = 0
  482.       End If
  483.     End If
  484.   Next
  485.   
  486.   'add the querydefs
  487.   If rbIncludeQDFs Then
  488.     For Each qdf In gdbCurrentDB.QueryDefs
  489.       rctl.AddItem qdf.Name
  490.       rctl.ItemData(rctl.NewIndex) = 1
  491.     Next
  492.   End If
  493.   
  494.   Exit Sub
  495.   
  496. FTLErr:
  497.   ShowError
  498. End Sub
  499.  
  500. '------------------------------------------------------------
  501. 'this function returns the numeric field type
  502. 'for the passed in string
  503. '------------------------------------------------------------
  504. Function GetFieldType(rFldType As String) As Integer
  505.   'return field length
  506.   If rFldType = "Text" Then
  507.     GetFieldType = dbText
  508.   Else
  509.     Select Case rFldType
  510.       Case "Counter"
  511.         GetFieldType = dbLong
  512.       Case "Boolean"
  513.         GetFieldType = dbBoolean
  514.       Case "Byte"
  515.         GetFieldType = dbByte
  516.       Case "Integer"
  517.         GetFieldType = dbInteger
  518.       Case "Long"
  519.         GetFieldType = dbLong
  520.       Case "Currency"
  521.         GetFieldType = dbCurrency
  522.       Case "Single"
  523.         GetFieldType = dbSingle
  524.       Case "Double"
  525.         GetFieldType = dbDouble
  526.       Case "Date/Time"
  527.         GetFieldType = dbDate
  528.       Case "Binary"
  529.         GetFieldType = dbLongBinary
  530.       Case "Memo"
  531.         GetFieldType = dbMemo
  532.     End Select
  533.   End If
  534.  
  535. End Function
  536.  
  537. '------------------------------------------------------------
  538. 'this function returns an appropriate field width for the
  539. 'field type passed in to be used for the control width on
  540. 'frmDynaSnap and frmTableObj forms
  541. '------------------------------------------------------------
  542. Function GetFieldWidth(rType As Integer)
  543.   Select Case rType
  544.     Case dbBoolean
  545.       GetFieldWidth = 850
  546.     Case dbByte
  547.       GetFieldWidth = 650
  548.     Case dbInteger
  549.       GetFieldWidth = 900
  550.     Case dbLong
  551.       GetFieldWidth = 1100
  552.     Case dbCurrency
  553.       GetFieldWidth = 1800
  554.     Case dbSingle
  555.       GetFieldWidth = 1800
  556.     Case dbDouble
  557.       GetFieldWidth = 2200
  558.     Case dbDate
  559.       GetFieldWidth = 2000
  560.     Case dbText
  561.       GetFieldWidth = 3250
  562.     Case dbLongBinary
  563.       GetFieldWidth = 3250
  564.     Case dbMemo
  565.       GetFieldWidth = 3250
  566.     Case Else
  567.       GetFieldWidth = 3250
  568.   End Select
  569.  
  570. End Function
  571.  
  572. '------------------------------------------------------------
  573. 'this function returns the INI file setting for the
  574. 'passed in item and section
  575. '------------------------------------------------------------
  576. Function GetINIString(ByVal vsItem As String, ByVal vsDefault As String) As String
  577.   GetINIString = GetSetting(APP_CATEGORY, App.Title, vsItem, vsDefault)
  578. End Function
  579.  
  580. '------------------------------------------------------------
  581. 'this sub hides the menus and toolbar that only apply
  582. 'when a database is open
  583. '------------------------------------------------------------
  584. Sub HideDBTools()
  585.   frmMDI.mnuDBClose.Enabled = False
  586.   frmMDI.mnuDBImpExp.Enabled = False
  587.   frmMDI.mnuUtil.Enabled = False
  588.   frmMDI.mnuUBar1.Visible = False
  589.   frmMDI.mnuUAttachments.Visible = False
  590.   frmMDI.mnuUGroupsUsers.Visible = False
  591.   frmMDI.mnuUSystemDB.Visible = False
  592.   frmMDI.tlbToolBar.Buttons("BeginTrans").Enabled = False
  593.   frmMDI.tlbToolBar.Buttons("Commit").Enabled = False
  594.   frmMDI.tlbToolBar.Buttons("Rollback").Enabled = False
  595. End Sub
  596.  
  597. '------------------------------------------------------------
  598. 'this sub displays the passed in message in the status
  599. 'bar on the bottom of the MDI form
  600. '------------------------------------------------------------
  601. Sub MsgBar(rsMsg As String, rPauseFlag As Integer)
  602.   If Len(rsMsg) = 0 Then
  603.     Screen.MousePointer = vbDefault
  604.     frmMDI.stsStatusBar.Panels(1).Text = MSG5
  605.   Else
  606.     If rPauseFlag Then
  607.       frmMDI.stsStatusBar.Panels(1).Text = rsMsg & MSG6
  608.     Else
  609.       frmMDI.stsStatusBar.Panels(1).Text = rsMsg
  610.     End If
  611.   End If
  612.   frmMDI.stsStatusBar.Refresh
  613. End Sub
  614.  
  615. '==================================================
  616. ' Routine: ObjectExists
  617. '
  618. ' Purpose: Determine whether or not a member exists
  619. '          same as MemberExists except that the 1st arg is declared
  620. '          as an object to allow passing in collections such as
  621. '          VBComponents, VBProjects, etc.
  622. ' Arguments:
  623. '   pColl: Name of Collection to check in
  624. '   sMemName: Name(key) of member to check for
  625. ' Outputs:
  626. '   True: member exists in collection
  627. '   False: member does not exist in the collection
  628. ' Maintenance: J$
  629. '==================================================
  630. Function ObjectExists(pColl As Object, sMemName As String) As Boolean
  631. Dim pObj As Object
  632.   
  633.   On Error Resume Next
  634.   Err = 0
  635.   Set pObj = pColl(sMemName)
  636.   ObjectExists = (Err = 0)
  637. End Function
  638.  
  639.  
  640. '------------------------------------------------------------
  641. 'this sub refreshs any table list passed in as an object
  642. '------------------------------------------------------------
  643. Sub RefreshTables(rListObject As Object)
  644.   On Error GoTo TRefErr
  645.  
  646.   Dim tdf As TableDef
  647.   Dim qdf As QueryDef
  648.   Dim sTmp As String
  649.     
  650.   Dim i As Integer
  651.     
  652.   MsgBar MSG7, True
  653.   Screen.MousePointer = vbHourglass
  654.  
  655.   'if this is called to refresh the database
  656.   'window, bypass the old method of
  657.   'filling a listbox with the table names
  658.   If rListObject Is Nothing Then GoTo LoadTreeView
  659.  
  660.   rListObject.Clear
  661.   If frmMDI.mnuPAllowSys.Checked Then
  662.     'list all tables
  663.     For Each tdf In gdbCurrentDB.TableDefs
  664.       If (tdf.Attributes And dbAttachedTable) = dbAttachedTable Then
  665.         If Left(tdf.Connect, 1) = ";" Then
  666.           'must be a Microsoft Access attached table
  667.           rListObject.AddItem tdf.Name & " -> Microsoft Access"
  668.         Else
  669.           'must be an ISAM attached table
  670.           rListObject.AddItem tdf.Name & " -> " & Left(tdf.Connect, InStr(tdf.Connect, ";") - 1)
  671.         End If
  672.       ElseIf (tdf.Attributes And dbAttachedODBC) = dbAttachedODBC Then
  673.         rListObject.AddItem tdf.Name & " -> ODBC"
  674.       Else
  675.         rListObject.AddItem tdf.Name
  676.       End If
  677.     Next
  678.   Else
  679.     'don't list system tables
  680.     For Each tdf In gdbCurrentDB.TableDefs
  681.       If (tdf.Attributes And dbSystemObject) = 0 Then
  682.         If (tdf.Attributes And dbAttachedTable) = dbAttachedTable Then
  683.           If Left(tdf.Connect, 1) = ";" Then
  684.             'must be a Microsoft Access attached table
  685.             rListObject.AddItem tdf.Name & " -> Microsoft Access"
  686.           Else
  687.             'must be an ISAM attached table
  688.             rListObject.AddItem tdf.Name & " -> " & Left(tdf.Connect, InStr(tdf.Connect, ";") - 1)
  689.           End If
  690.         ElseIf (tdf.Attributes And dbAttachedODBC) = dbAttachedODBC Then
  691.           rListObject.AddItem tdf.Name & " -> ODBC"
  692.         Else
  693.           rListObject.AddItem tdf.Name
  694.         End If
  695.       End If
  696.     Next
  697.   End If
  698.   'select the 1st item if there is any
  699.   If rListObject.ListCount > 0 Then
  700.     rListObject.ListIndex = 0
  701.   End If
  702.   
  703. LoadTreeView:
  704.   frmDatabase.LoadDatabase
  705.   
  706.   Screen.MousePointer = vbDefault
  707.   MsgBar vbNullString, False
  708.   Exit Sub
  709.  
  710. TRefErr:
  711.   ShowError
  712. End Sub
  713.  
  714. '------------------------------------------------------------
  715. 'this function returns the size of the field type
  716. 'passed in for use on the frmAddField form
  717. '------------------------------------------------------------
  718. Function SetFldProperties(rnType As Integer) As Integer
  719.   'return field length
  720.   Select Case rnType
  721.     Case dbBoolean
  722.       SetFldProperties = 1
  723.     Case dbByte
  724.       SetFldProperties = 1
  725.     Case dbInteger
  726.       SetFldProperties = 2
  727.     Case dbLong
  728.       SetFldProperties = 4
  729.     Case dbCurrency
  730.       SetFldProperties = 8
  731.     Case dbSingle
  732.       SetFldProperties = 4
  733.     Case dbDouble
  734.       SetFldProperties = 8
  735.     Case dbDate
  736.       SetFldProperties = 8
  737.     Case dbText
  738.       SetFldProperties = 50
  739.     Case dbLongBinary
  740.       SetFldProperties = 0
  741.     Case dbMemo
  742.       SetFldProperties = 0
  743.   End Select
  744. End Function
  745.  
  746. '------------------------------------------------------------
  747. 'this sub shows the menus and toolbar that only apply
  748. 'when a database is open
  749. '------------------------------------------------------------
  750. Sub ShowDBTools()
  751.   Dim sTmp As String
  752.  
  753.   frmMDI.mnuDBClose.Enabled = True
  754.   frmMDI.mnuDBImpExp.Enabled = True
  755.   frmMDI.mnuUtil.Enabled = True
  756.   frmMDI.tlbToolBar.Buttons("BeginTrans").Enabled = True
  757.   frmMDI.tlbToolBar.Buttons("Commit").Enabled = False
  758.   frmMDI.tlbToolBar.Buttons("Rollback").Enabled = False
  759.   frmMDI.tlbToolBar.Refresh
  760.  
  761.   'set general items that apply/don't apply to MDBs
  762.   If gsDataType = gsMSACCESS Then
  763.     frmMDI.mnuUBar1.Visible = True
  764.     frmMDI.mnuUAttachments.Visible = True
  765.     frmMDI.mnuUGroupsUsers.Visible = True
  766.     frmMDI.mnuUSystemDB.Visible = True
  767.     frmSQL.cmdSaveQueryDef.Visible = True
  768.     frmMDI.mnuDBPURename.Visible = True
  769.   Else
  770.     frmSQL.cmdSaveQueryDef.Visible = False
  771.     frmMDI.mnuDBPURename.Visible = False
  772.   End If
  773.  
  774.   'set ODBC specific items
  775.   If gsDataType = gsSQLDB Then
  776.     If gnRSType = gnRS_TABLE Then
  777.       frmMDI.tlbToolBar.Buttons("Dynaset").Value = tbrPressed
  778.       gnRSType = gnRS_DYNASET
  779.     End If
  780.     frmMDI.tlbToolBar.Buttons("PassThrough").Visible = True
  781.     frmMDI.tlbToolBar.Buttons("Table").Visible = False
  782.   Else
  783.     If gnRSType = gnRS_PASSTHRU Then
  784.       frmMDI.tlbToolBar.Buttons("Dynaset").Value = tbrPressed
  785.       gnRSType = gnRS_DYNASET
  786.     End If
  787.     frmMDI.tlbToolBar.Buttons("PassThrough").Visible = False
  788.     frmMDI.tlbToolBar.Buttons("Table").Visible = True
  789.   End If
  790.   frmMDI.tlbToolBar.Refresh
  791.   'show the 2 main child forms
  792.   frmDatabase.Show
  793.   frmSQL.Show
  794. End Sub
  795.  
  796. '------------------------------------------------------------
  797. 'this sub displays the error message with it's Err code
  798. 'and prompts to show the Errors collection if it
  799. 'is a data access type error
  800. '------------------------------------------------------------
  801. Sub ShowError()
  802.   Dim sTmp As String
  803.  
  804.   Screen.MousePointer = vbDefault
  805.   MsgBar vbNullString, False
  806.  
  807.   sTmp = "The following Error occurred:" & vbCrLf & vbCrLf
  808.   'add the error string
  809.   sTmp = sTmp & Err.Description & vbCrLf
  810.   'add the error number
  811.   sTmp = sTmp & MSG8 & Err
  812.   
  813.   Beep
  814.   'check to see if the error is from the db errors collection
  815.   If DBEngine.Errors.Count > 0 Then
  816.     If DBEngine.Errors(0).Number = Err Then
  817.       'add the prompt to display the errors collection
  818.       sTmp = sTmp & vbCrLf & vbCrLf & MSG9
  819.       'beep and show the error
  820.       If MsgBox(sTmp, vbYesNo + vbQuestion) = vbYes Then
  821.         RefreshErrors
  822.       End If
  823.     Else
  824.       MsgBox sTmp
  825.     End If
  826.   Else
  827.     MsgBox sTmp
  828.   End If
  829.  
  830. End Sub
  831.  
  832. '------------------------------------------------------------
  833. 'this function strips the attached table connect string off
  834. '------------------------------------------------------------
  835. Function StripConnect(rsTblName As String) As String
  836.   If InStr(rsTblName, "->") > 0 Then
  837.     StripConnect = Left(rsTblName, InStr(rsTblName, "->") - 2)
  838.   Else
  839.     StripConnect = rsTblName
  840.   End If
  841.  
  842. End Function
  843.  
  844. '------------------------------------------------------------
  845. 'this function strips the [] off of data objects
  846. '------------------------------------------------------------
  847. Function StripBrackets(rsObjName As String) As String
  848.   'add brackets to object names w/ spaces in them
  849.   If Mid(rsObjName, 1, 1) = "[" Then
  850.     StripBrackets = Mid(rsObjName, 2, Len(rsObjName) - 2)
  851.   Else
  852.     StripBrackets = rsObjName
  853.   End If
  854.  
  855. End Function
  856.  
  857. '------------------------------------------------------------
  858. 'this function strips the file name from a path\file string
  859. '------------------------------------------------------------
  860. Function StripFileName(rsFileName As String) As String
  861.   On Error Resume Next
  862.   Dim i As Integer
  863.  
  864.   For i = Len(rsFileName) To 1 Step -1
  865.     If Mid(rsFileName, i, 1) = "\" Then
  866.       Exit For
  867.     End If
  868.   Next
  869.  
  870.   StripFileName = Mid(rsFileName, 1, i - 1)
  871.  
  872. End Function
  873.  
  874. '------------------------------------------------------------
  875. 'this function strips the non ACSII chars off memo field
  876. 'data before displaying it (not sure this is always needed)
  877. '------------------------------------------------------------
  878. Function StripNonAscii(rvntVal As Variant) As String
  879.   Dim i As Integer
  880.   Dim sTmp As String
  881.  
  882.   'stubbed out to enable DBCS chars
  883.   StripNonAscii = rvntVal
  884.   Exit Function
  885.  
  886.   For i = 1 To Len(rvntVal)
  887.     If Asc(Mid(rvntVal, i, 1)) < 32 Or Asc(Mid(rvntVal, i, 1)) > 126 Then
  888.       sTmp = sTmp & " "
  889.     Else
  890.       sTmp = sTmp & Mid(rvntVal, i, 1)
  891.     End If
  892.   Next
  893.  
  894.   StripNonAscii = sTmp
  895.  
  896. End Function
  897.  
  898. '------------------------------------------------------------
  899. 'strips the owner off of ODBC table names
  900. '------------------------------------------------------------
  901. Function StripOwner(rsTblName As String) As String
  902.  
  903.   If InStr(rsTblName, ".") > 0 Then
  904.     rsTblName = Mid(rsTblName, InStr(rsTblName, ".") + 1, Len(rsTblName))
  905.   End If
  906.   StripOwner = rsTblName
  907.  
  908. End Function
  909.  
  910. '------------------------------------------------------------
  911. 'returns the true or false string
  912. '------------------------------------------------------------
  913. Function stTrueFalse(rvntTF As Variant) As String
  914.   If rvntTF Then
  915.     stTrueFalse = "True"
  916.   Else
  917.     stTrueFalse = "False"
  918.   End If
  919. End Function
  920.  
  921. '------------------------------------------------------------
  922. 'returns "" if a field is Null
  923. '------------------------------------------------------------
  924. Function vFieldVal(rvntFieldVal As Variant) As Variant
  925.   If IsNull(rvntFieldVal) Then
  926.     vFieldVal = vbNullString
  927.   Else
  928.     vFieldVal = CStr(rvntFieldVal)
  929.   End If
  930. End Function
  931.  
  932. '------------------------------------------------------------
  933. 'loads all saved INI settings for VisData
  934. '------------------------------------------------------------
  935. Sub LoadINISettings()
  936.   On Error Resume Next
  937.   
  938.   Dim sTmp As String
  939.   Dim x As Integer
  940.  
  941.   glQueryTimeout = Val(GetINIString("QueryTimeout", "5"))
  942.   glLoginTimeout = Val(GetINIString("LoginTimeout", "20"))
  943.   
  944.   
  945.   frmMDI.mnuPOpenOnStartup.Checked = Val(GetINIString("OpenOnStartup", "0"))
  946.   frmMDI.mnuPAllowSys.Checked = Val(GetINIString("AllowSys", "0"))
  947.  
  948.   'get the most recently used databases
  949.   For x = 1 To 8
  950.     sTmp = GetINIString("MRUDatabase" & x, "")
  951.     If Len(sTmp) > 0 Then
  952.       frmMDI.mnuBarMRU.Visible = True
  953.       frmMDI.mnuDBMRU(x).Caption = "&" & x & " " & sTmp
  954.       frmMDI.mnuDBMRU(x).Visible = True
  955.       sTmp = GetINIString("MRUConnect" & x, "")
  956.       frmMDI.mnuDBMRU(x).Tag = sTmp
  957.     End If
  958.   Next
  959.  
  960.   'get the last used database out of the INI file
  961.   gsDataType = GetINIString("DataType", vbNullString)
  962.   gsDBName = GetINIString("DatabaseName", vbNullString)
  963.   gsODBCDatasource = GetINIString("ODBCDatasource", vbNullString)
  964.   gsODBCDatabase = GetINIString("ODBCDatabase", vbNullString)
  965.   gsODBCUserName = GetINIString("ODBCUserName", vbNullString)
  966.   gsODBCPassword = GetINIString("ODBCPassword", vbNullString)
  967.   gsODBCDriver = GetINIString("ODBCDriver", vbNullString)
  968.   gsODBCServer = GetINIString("ODBCServer", vbNullString)
  969.  
  970.   sTmp = GetINIString("ViewMode", CStr(gnFORM_NODATACTL))
  971.   Select Case Val(sTmp)
  972.     Case gnFORM_NODATACTL
  973.       gnFormType = gnFORM_NODATACTL
  974.     Case gnFORM_DATACTL
  975.       gnFormType = gnFORM_DATACTL
  976.     Case gnFORM_DATAGRID
  977.       gnFormType = gnFORM_DATAGRID
  978.   End Select
  979.   sTmp = GetINIString("RecordsetType", CStr(vbRSTypeDynaset))
  980.   Select Case Val(sTmp)
  981.     Case vbRSTypeTable
  982.       gnRSType = gnRS_TABLE
  983.     Case vbRSTypeDynaset
  984.       gnRSType = gnRS_DYNASET
  985.     Case vbRSTypeSnapShot
  986.       gnRSType = gnRS_SNAPSHOT
  987.     Case gnRS_PASSTHRU
  988.       gnRSType = gnRS_PASSTHRU
  989.   End Select
  990.   
  991.   DoEvents
  992.   Select Case gnFormType
  993.     Case gnFORM_NODATACTL
  994.       frmMDI.tlbToolBar.Buttons("NoDataControl").Value = tbrPressed
  995.     Case gnFORM_DATACTL
  996.       frmMDI.tlbToolBar.Buttons("DataControl").Value = tbrPressed
  997.     Case gnFORM_DATAGRID
  998.       frmMDI.tlbToolBar.Buttons("DBGrid").Value = tbrPressed
  999.   End Select
  1000.   Select Case gnRSType
  1001.     Case vbRSTypeDynaset
  1002.       frmMDI.tlbToolBar.Buttons("Dynaset").Value = tbrPressed
  1003.     Case vbRSTypeSnapShot
  1004.       frmMDI.tlbToolBar.Buttons("Snapshot").Value = tbrPressed
  1005.     Case vbRSTypeTable
  1006.       frmMDI.tlbToolBar.Buttons("Table").Value = tbrPressed
  1007.     Case gnRS_PASSTHRU
  1008.       frmMDI.tlbToolBar.Buttons("PassThrough").Value = tbrPressed
  1009.   End Select
  1010.   
  1011. End Sub
  1012.  
  1013. '------------------------------------------------------------
  1014. 'saves current VisData values in VISDATA.INI
  1015. '------------------------------------------------------------
  1016. Sub SaveINISettings()
  1017.   On Error Resume Next
  1018.  
  1019.   Dim i As Integer
  1020.   
  1021.   SaveSetting APP_CATEGORY, App.Title, "DataType", gsDataType
  1022.   SaveSetting APP_CATEGORY, App.Title, "DatabaseName", gsDBName
  1023.   SaveSetting APP_CATEGORY, App.Title, "ODBCDatasource", gsODBCDatasource
  1024.   SaveSetting APP_CATEGORY, App.Title, "ODBCDatabase", gsODBCDatabase
  1025.   SaveSetting APP_CATEGORY, App.Title, "ODBCUserName", gsODBCUserName
  1026.   SaveSetting APP_CATEGORY, App.Title, "ODBCPassword", gsODBCPassword
  1027.   SaveSetting APP_CATEGORY, App.Title, "ODBCDriver", gsODBCDriver
  1028.   SaveSetting APP_CATEGORY, App.Title, "ODBCServer", gsODBCServer
  1029.   SaveSetting APP_CATEGORY, App.Title, "QueryTimeout", glQueryTimeout
  1030.   SaveSetting APP_CATEGORY, App.Title, "LoginTimeout", glLoginTimeout
  1031.   DBEngine.LoginTimeout = glLoginTimeout
  1032.   SaveSetting APP_CATEGORY, App.Title, "ViewMode", gnFormType
  1033.   SaveSetting APP_CATEGORY, App.Title, "RecordsetType", gnRSType
  1034.   
  1035.   SaveSetting APP_CATEGORY, App.Title, "OpenOnStartup", IIf(frmMDI.mnuPOpenOnStartup.Checked, "-1", "0")
  1036.   SaveSetting APP_CATEGORY, App.Title, "AllowSys", IIf(frmMDI.mnuPAllowSys.Checked, "-1", "0")
  1037.  
  1038.   For i = 1 To 8
  1039.     If frmMDI.mnuDBMRU(i).Visible Then
  1040.       SaveSetting APP_CATEGORY, App.Title, "MRUDatabase" & i, Mid(frmMDI.mnuDBMRU(i).Caption, 4, Len(frmMDI.mnuDBMRU(i).Caption))
  1041.       SaveSetting APP_CATEGORY, App.Title, "MRUConnect" & i, frmMDI.mnuDBMRU(i).Tag
  1042.     Else
  1043.       SaveSetting APP_CATEGORY, App.Title, "MRUDatabase" & i, ""
  1044.       SaveSetting APP_CATEGORY, App.Title, "MRUConnect" & i, ""
  1045.     End If
  1046.   Next
  1047.  
  1048.   SaveSetting APP_CATEGORY, App.Title, "WindowState", frmMDI.WindowState
  1049.   If frmMDI.WindowState = vbNormal Then
  1050.     SaveSetting APP_CATEGORY, App.Title, "WindowTop", frmMDI.Top
  1051.     SaveSetting APP_CATEGORY, App.Title, "WindowLeft", frmMDI.Left
  1052.     SaveSetting APP_CATEGORY, App.Title, "WindowWidth", frmMDI.Width
  1053.     SaveSetting APP_CATEGORY, App.Title, "WindowHeight", frmMDI.Height
  1054.   End If
  1055.   SaveSetting APP_CATEGORY, App.Title, "ViewMode", gnFormType
  1056.   SaveSetting APP_CATEGORY, App.Title, "RecordsetType", gnRSType
  1057.  
  1058. End Sub
  1059.  
  1060. '------------------------------------------------------------
  1061. 'this sub will open the appropriate data type form and
  1062. 'display the appropriate msg in the status bar based on
  1063. 'user selected options on the main MDI form
  1064. '------------------------------------------------------------
  1065. Sub OpenTable(rName As String)
  1066.   On Error GoTo OpenTableErr
  1067.  
  1068.   Dim rsTmp As Recordset
  1069.   Dim sTmp As String
  1070.   Dim nAttach As Integer
  1071.   Dim frmTmp As Form
  1072.   
  1073.   If gsDataType = gsMSACCESS Then   'look for attached tables if it's an MDB
  1074.     If (gdbCurrentDB.TableDefs(rName).Attributes And dbAttachedTable) = dbAttachedTable Then
  1075.       nAttach = 1
  1076.     ElseIf (gdbCurrentDB.TableDefs(rName).Attributes And dbAttachedODBC) = dbAttachedODBC Then
  1077.       nAttach = 2
  1078.     End If
  1079.     If nAttach > 0 And gnRSType = gnRS_TABLE Then
  1080.       Beep
  1081.       If MsgBox(MSG10, vbYesNo + vbQuestion) = vbYes Then
  1082.         frmMDI.tlbToolBar.Buttons("Dynaset").Value = tbrPressed         'reset to dynaset
  1083.       Else
  1084.         Exit Sub
  1085.       End If
  1086.     End If
  1087.   End If
  1088.   
  1089.   If nAttach > 0 Then
  1090.     If gnRSType = gnRS_DYNASET Then
  1091.       sTmp = MSG11
  1092.     ElseIf gnRSType = gnRS_SNAPSHOT Then
  1093.       sTmp = MSG12
  1094.     End If
  1095.   Else
  1096.     If gnRSType = gnRS_TABLE Then
  1097.       sTmp = MSG13
  1098.     ElseIf gnRSType = gnRS_DYNASET Then
  1099.       sTmp = MSG14
  1100.     ElseIf gnRSType = gnRS_SNAPSHOT Then
  1101.       sTmp = MSG15
  1102.     ElseIf gnRSType = gnRS_PASSTHRU Then
  1103.       sTmp = MSG16
  1104.     End If
  1105.   End If
  1106.   
  1107.   MsgBar sTmp, True
  1108.   
  1109.   Screen.MousePointer = vbHourglass
  1110.   If gnRSType = gnRS_TABLE Then
  1111.     Set rsTmp = gdbCurrentDB.OpenRecordset(rName, dbOpenTable)
  1112.     sTmp = "Table:"
  1113.   ElseIf gnRSType = gnRS_DYNASET Then
  1114.     Set rsTmp = gdbCurrentDB.OpenRecordset(rName, dbOpenDynaset)
  1115.     sTmp = "Dynaset:"
  1116.   ElseIf gnRSType = gnRS_SNAPSHOT Then
  1117.     Set rsTmp = gdbCurrentDB.OpenRecordset(rName, dbOpenSnapshot)
  1118.     sTmp = "Snapshot:"
  1119.   ElseIf gnRSType = gnRS_PASSTHRU Then
  1120.     Set rsTmp = gdbCurrentDB.OpenRecordset(rName, dbOpenSnapshot, dbSQLPassThrough)
  1121.     sTmp = "Passthrough Snapshot:"
  1122.   End If
  1123.   Screen.MousePointer = vbDefault
  1124.   
  1125.   If gnFormType = gnFORM_NODATACTL Then
  1126.     If gnRSType = gnRS_TABLE Then
  1127.       Set frmTmp = New frmTableObj
  1128.       sTmp = "Table:"
  1129.     Else
  1130.       Set frmTmp = New frmDynaSnap
  1131.     End If
  1132.   ElseIf gnFormType = gnFORM_DATACTL Then
  1133.     Set frmTmp = New frmDataControl
  1134.   ElseIf gnFormType = gnFORM_DATAGRID Then
  1135.     Set frmTmp = New frmDataGrid
  1136.   End If
  1137.   
  1138.   Set frmTmp.mrsFormRecordset = rsTmp
  1139.   frmTmp.Caption = sTmp & rName
  1140.   frmTmp.Show
  1141.  
  1142.   MsgBar vbNullString, False
  1143.   
  1144.   Exit Sub
  1145. OpenTableErr:
  1146.   ShowError
  1147. End Sub
  1148.  
  1149. '------------------------------------------------------------
  1150. 'opens a QueryDef with the user selected form type
  1151. '------------------------------------------------------------
  1152. Sub OpenQuery(rName As String, bTemp As Boolean)
  1153.   On Error GoTo OpenQueryErr
  1154.  
  1155.   Dim sTmp As String
  1156.   Dim rsTmp As Recordset
  1157.   Dim qdfTmp As QueryDef
  1158.   Dim sQueryType As String
  1159.   Dim frmTmp As Form
  1160.   Dim nDoIt As Integer
  1161.   Dim bReturnsRows As Boolean
  1162.  
  1163.   If bTemp Then
  1164.     Set qdfTmp = gdbCurrentDB.CreateQueryDef("", rName)
  1165.     If MsgBox(MSG17, vbYesNo + vbQuestion + vbDefaultButton2) = vbYes Then
  1166.       sTmp = InputBox(MSG18)
  1167.       If Len(sTmp) > 0 Then
  1168.         qdfTmp.Connect = sTmp
  1169.       End If
  1170.     End If
  1171.     'assume it is non row returning to begin with
  1172.     bReturnsRows = False
  1173.   Else
  1174.     Set qdfTmp = gdbCurrentDB.QueryDefs(rName)
  1175.     sQueryType = ActionQueryType(qdfTmp)
  1176.     If qdfTmp.Type <> dbQSQLPassThrough Then
  1177.       'not a sql pass through so we need to set ReturnsRecords
  1178.       If qdfTmp.Type = 0 Or qdfTmp.Type = dbQCrosstab Then
  1179.         bReturnsRows = True
  1180.       Else
  1181.         bReturnsRows = False
  1182.       End If
  1183.     Else
  1184.       'get it from the qdf if it is passthrough
  1185.       bReturnsRows = qdfTmp.ReturnsRecords
  1186.     End If
  1187.   End If
  1188.   
  1189.   If bReturnsRows And (gnRSType = gnRS_TABLE) Then
  1190.     Beep
  1191.     If MsgBox(MSG19, vbYesNo + vbQuestion) = vbYes Then
  1192.       frmMDI.tlbToolBar.Buttons("Dynaset").Value = tbrPressed         'reset to recordset
  1193.     Else
  1194.       Exit Sub
  1195.     End If
  1196.   End If
  1197.   
  1198.   
  1199.   If bReturnsRows Then
  1200.     SetQDFParams qdfTmp
  1201. MakeDynaset:
  1202.     Screen.MousePointer = vbHourglass
  1203.     If qdfTmp.Type = dbQSQLPassThrough Then
  1204.       MsgBar MSG16, True
  1205.       Set rsTmp = qdfTmp.OpenRecordset(dbOpenSnapshot, dbSQLPassThrough)
  1206.     ElseIf gnRSType = gnRS_SNAPSHOT Then
  1207.       MsgBar MSG20, True
  1208.       Set rsTmp = qdfTmp.OpenRecordset(dbOpenSnapshot)
  1209.     Else
  1210.       MsgBar MSG21, True
  1211.       Set rsTmp = qdfTmp.OpenRecordset(dbOpenDynaset)
  1212.     End If
  1213.     Screen.MousePointer = vbDefault
  1214.     
  1215.     If gnFormType = gnFORM_NODATACTL Then
  1216.       Set frmTmp = New frmDynaSnap
  1217.     ElseIf gnFormType = gnFORM_DATACTL Then
  1218.       Set frmTmp = New frmDataControl
  1219.       If qdfTmp.Parameters.Count > 0 Then
  1220.         frmTmp.mbIsParameterized = True
  1221.       End If
  1222.     ElseIf gnFormType = gnFORM_DATAGRID Then
  1223.       Set frmTmp = New frmDataGrid
  1224.     End If
  1225.     
  1226.     Set frmTmp.mrsFormRecordset = rsTmp
  1227.     If Len(qdfTmp.SQL) > 50 Then
  1228.       frmTmp.Caption = MSG22
  1229.     Else
  1230.       frmTmp.Caption = qdfTmp.SQL
  1231.     End If
  1232.     frmTmp.Show
  1233.     
  1234.   Else
  1235.     Screen.MousePointer = vbDefault
  1236.     If Len(sQueryType) > 0 Then
  1237.       nDoIt = MsgBox(MSG23 & sQueryType & MSG24, vbYesNo + vbQuestion)
  1238.     Else
  1239.       'no name so just try to execute it
  1240.       nDoIt = vbYes
  1241.     End If
  1242.     If nDoIt = vbYes Then
  1243.       SetQDFParams qdfTmp
  1244.       Screen.MousePointer = vbHourglass
  1245.       MsgBar MSG25, True
  1246.       qdfTmp.Execute
  1247.       If gdbCurrentDB.RecordsAffected > 0 Then
  1248.         If gbTransPending Then gbDBChanged = True
  1249.       End If
  1250.     End If
  1251.   End If
  1252.   
  1253.   MsgBar vbNullString, False
  1254.   
  1255.   Exit Sub
  1256. OpenQueryErr:
  1257.   If Err = 3065 Or Err = 3078 Then
  1258.     'row returning so try to create recordset
  1259.     Resume MakeDynaset
  1260.   End If
  1261.   ShowError
  1262. End Sub
  1263.  
  1264. '------------------------------------------------------------
  1265. 'this sub display all field data in the current row
  1266. 'on the table and dynasnap forms
  1267. '------------------------------------------------------------
  1268. Sub DisplayCurrentRecord(frm As Object, rec As Recordset, lCnt As Long, bNew As Integer)
  1269.   Dim i As Integer
  1270.   Dim sCurrStat As String
  1271.   Dim lCurrRec As Long
  1272.   Dim bNoInd As Integer
  1273.  
  1274.   On Error GoTo DCRErr
  1275.  
  1276.   Screen.MousePointer = vbHourglass
  1277.  
  1278.   sCurrStat = "Row "
  1279.    
  1280.   'check to see if a table w/ 0 indexes is in use
  1281.   If rec.Type = dbOpenTable Then
  1282.     If gdbCurrentDB(rec.Name).Indexes.Count = 0 Then
  1283.       bNoInd = True
  1284.     End If
  1285.   End If
  1286.    
  1287.   'check for an empty recordset
  1288.   If rec.RecordCount > 0 Then
  1289.     lCurrRec = (lCnt * (rec.PercentPosition * 0.01)) + 1
  1290.   End If
  1291.      
  1292.   'check BOF/EOF flag so we know if we
  1293.   'are sitting on a valid record
  1294.   If bNew Then
  1295.     If bNoInd Then
  1296.       sCurrStat = lCnt & " Rows"
  1297.     Else
  1298.       sCurrStat = lCurrRec & "/" & lCnt
  1299.     End If
  1300.   Else
  1301.     If rec.BOF Then
  1302.       sCurrStat = "(BOF)/" & lCnt
  1303.       ClearDataFields frm, rec.Fields.Count
  1304.     ElseIf rec.EOF Then
  1305.       sCurrStat = "(EOF)/" & lCnt
  1306.       ClearDataFields frm, rec.Fields.Count
  1307.     Else
  1308.       If bNoInd Then
  1309.         sCurrStat = lCnt & " Rows"
  1310.       Else
  1311.         sCurrStat = lCurrRec & "/" & lCnt
  1312.       End If
  1313.       'place the data in the form fields
  1314.       For i = 0 To rec.Fields.Count - 1
  1315.         If rec(i).Type = dbMemo Then
  1316.           If rec(i).FieldSize() < gnGETCHUNK_CUTOFF Then
  1317.             frm.txtFieldData(i).Text = StripNonAscii(vFieldVal(rec(i)))
  1318.           Else
  1319.             frm.txtFieldData(i).Text = StripNonAscii(vFieldVal(rec(i).GetChunk(0, gnGETCHUNK_CUTOFF)))
  1320.           End If
  1321.         ElseIf rec(i).Type = dbText Then
  1322.           frm.txtFieldData(i).Text = vFieldVal(rec(i))
  1323.         Else
  1324.           frm.txtFieldData(i).Text = vFieldVal(rec(i))
  1325.         End If
  1326.       Next
  1327.     End If
  1328.   End If
  1329.   If rec.Updatable = False Then sCurrStat = sCurrStat & MSG26
  1330.   frm.lblStatus.Caption = sCurrStat
  1331.   Screen.MousePointer = vbDefault
  1332.   Exit Sub
  1333.  
  1334. DCRErr:
  1335.   ShowError
  1336.   Resume Next    'so we can try and display as much data as possible
  1337. End Sub
  1338.  
  1339. '------------------------------------------------------------
  1340. 'this function checks to see if the passed in name exists
  1341. 'in either the Tabledefs or Querydefs collection
  1342. 'it found, it prompts to delete it and returns false
  1343. 'if the user selects to delete it or true if not
  1344. 'if not found, it returns false
  1345. '------------------------------------------------------------
  1346. Function DupeTableName(rName As String) As Integer
  1347.   On Error GoTo DTNErr
  1348.  
  1349.   Dim tdf As TableDef
  1350.   Dim qdf As QueryDef
  1351.   Dim i As Integer
  1352.  
  1353.   For Each tdf In gdbCurrentDB.TableDefs
  1354.     If UCase(tdf.Name) = UCase(rName) Then
  1355.       If MsgBox(MSG27, vbYesNo + vbQuestion) = vbYes Then
  1356.         gdbCurrentDB.TableDefs.Delete rName
  1357.         DupeTableName = False
  1358.       Else
  1359.         DupeTableName = True
  1360.       End If
  1361.       Exit Function
  1362.     End If
  1363.   Next
  1364.  
  1365.   If gsDataType = gsMSACCESS Then
  1366.     For Each qdf In gdbCurrentDB.QueryDefs
  1367.       If UCase(qdf.Name) = UCase(rName) Then
  1368.         If MsgBox(MSG28, vbYesNo + vbQuestion) = vbYes Then
  1369.           gdbCurrentDB.QueryDefs.Delete rName
  1370.           DupeTableName = False
  1371.         Else
  1372.           DupeTableName = True
  1373.         End If
  1374.         Exit Function
  1375.       End If
  1376.     Next
  1377.   End If
  1378.  
  1379.   DupeTableName = False
  1380.   Exit Function
  1381.  
  1382. DTNErr:
  1383.   ShowError
  1384.   DupeTableName = False
  1385. End Function
  1386.  
  1387. '------------------------------------------------------------
  1388. 'this sub unloads all forms except for the
  1389. 'SQL, Tables and MDI form
  1390. '------------------------------------------------------------
  1391. Sub UnloadAllForms()
  1392.   On Error Resume Next
  1393.   
  1394.   Dim i As Integer
  1395.   
  1396.   'close all forms except for the Tables and SQL forms
  1397.   For i = Forms.Count - 1 To 1 Step -1
  1398.     Unload Forms(i)
  1399.   Next
  1400. End Sub
  1401.  
  1402. '------------------------------------------------------------
  1403. 'this sub walks the parameters collection in a parameterized
  1404. 'query and prompts the user for a value for each parameter
  1405. '------------------------------------------------------------
  1406. Sub SetQDFParams(rqdf As QueryDef)
  1407.   On Error GoTo SPErr
  1408.   
  1409.   Dim prm As Parameter
  1410.   Dim sTmp As String
  1411.   
  1412.   For Each prm In rqdf.Parameters
  1413.     'get the value from the user
  1414.     sTmp = InputBox(MSG29, "'" & prm.Name & "':")
  1415.     'store the value
  1416.     prm.Value = CVar(sTmp)
  1417.   Next
  1418.   
  1419.   Exit Sub
  1420.     
  1421. SPErr:
  1422.   ShowError
  1423. End Sub
  1424.  
  1425. '------------------------------------------------------------
  1426. 'this sub refreshs the Error form with the latest Errors
  1427. '------------------------------------------------------------
  1428. Sub RefreshErrors()
  1429.   On Error GoTo RErr
  1430.   
  1431.   Dim errObj As Error
  1432.   Dim i As Integer
  1433.  
  1434.   If DBEngine.Errors.Count = 0 Then
  1435.     MsgBox MSG30, 48
  1436.     Unload frmErrors
  1437.     Exit Sub
  1438.   End If
  1439.  
  1440.   frmErrors.Show
  1441.   frmErrors.lstErrors.Clear
  1442.   For i = 0 To DBEngine.Errors.Count - 1
  1443.     Set errObj = DBEngine.Errors(i)
  1444.     frmErrors.lstErrors.AddItem errObj.Number & vbTab & errObj.Source & vbTab & errObj.Description
  1445.   Next
  1446.   frmErrors.SetFocus
  1447.  
  1448.   Exit Sub
  1449.   
  1450. RErr:
  1451.   MsgBox MSG31, 48
  1452.   Unload frmErrors
  1453.   Exit Sub
  1454. End Sub
  1455.  
  1456. '------------------------------------------------------------
  1457. 'this sub adds the just opened database to the most recently
  1458. 'used list in the File menu
  1459. '------------------------------------------------------------
  1460. Sub AddMRU()
  1461.   On Error GoTo AMErr
  1462.  
  1463.   Dim i As Integer, j As Integer
  1464.  
  1465.   '1st look to see if it alread exists and swap it if it does
  1466.   For i = 1 To 8
  1467.     If UCase(Mid(frmMDI.mnuDBMRU(i).Caption, 4, Len(frmMDI.mnuDBMRU(i).Caption))) = UCase(gsDBName) Then
  1468.       For j = i To 2 Step -1
  1469.         frmMDI.mnuDBMRU(j).Caption = "&" & j & " " & Mid(frmMDI.mnuDBMRU(j - 1).Caption, 4, Len(frmMDI.mnuDBMRU(j - 1).Caption))
  1470.         frmMDI.mnuDBMRU(j).Tag = frmMDI.mnuDBMRU(j - 1).Tag
  1471.       Next
  1472.       GoTo Finish
  1473.     End If
  1474.   Next
  1475.  
  1476.   'wasn't there so move everything down one
  1477.   For i = 7 To 1 Step -1
  1478.     frmMDI.mnuDBMRU(i + 1).Caption = "&" & i + 1 & " " & Mid(frmMDI.mnuDBMRU(i).Caption, 4, Len(frmMDI.mnuDBMRU(i).Caption))
  1479.     frmMDI.mnuDBMRU(i + 1).Tag = frmMDI.mnuDBMRU(i).Tag
  1480.   Next
  1481.  
  1482. Finish:
  1483.   frmMDI.mnuDBMRU(1).Caption = "&1 " & gsDBName
  1484.   If Len(gdbCurrentDB.Connect) = 0 Then
  1485.     'handle the Access case where there is no connect string
  1486.     frmMDI.mnuDBMRU(1).Tag = gsMSACCESS
  1487.   Else
  1488.     frmMDI.mnuDBMRU(1).Tag = gdbCurrentDB.Connect
  1489.   End If
  1490.   frmMDI.mnuBarMRU.Visible = True
  1491.   For i = 1 To 8
  1492.     If Len(Mid(frmMDI.mnuDBMRU(i).Caption, 4, Len(frmMDI.mnuDBMRU(i).Caption))) > 0 Then
  1493.       frmMDI.mnuDBMRU(i).Visible = True
  1494.     End If
  1495.   Next
  1496.  
  1497.   Exit Sub
  1498.  
  1499. AMErr:
  1500.   ShowError
  1501. End Sub
  1502.  
  1503. '------------------------------------------------------------
  1504. 'this sub breaks out the parts of a ODBC connect string
  1505. 'and assigns them to the global ODBC variables
  1506. '------------------------------------------------------------
  1507. Sub GetODBCConnectParts(rsConnect As String)
  1508.   On Error Resume Next
  1509.   
  1510.   Dim i As Integer
  1511.   Dim sTmp As String
  1512.   
  1513.   'process the connect string just in case the
  1514.   'values came from the ODBC dialogs
  1515.   If InStr(rsConnect, "=") Then
  1516.     i = 1
  1517.     While i <= Len(rsConnect) + 1
  1518.       If Mid(rsConnect, i, 1) = ";" Or i = Len(rsConnect) + 1 Then
  1519.         If Len(sTmp) > 0 And InStr(sTmp, "=") > 0 Then
  1520.           Select Case Mid(sTmp, 1, InStr(1, sTmp, "=") - 1)
  1521.             Case "DSN"
  1522.               gsODBCDatasource = Mid(sTmp, InStr(1, sTmp, "=") + 1, Len(sTmp))
  1523.             Case "DATABASE"
  1524.               gsODBCDatabase = Mid(sTmp, InStr(1, sTmp, "=") + 1, Len(sTmp))
  1525.             Case "DBQ"
  1526.               gsODBCDatabase = Mid(sTmp, InStr(1, sTmp, "=") + 1, Len(sTmp))
  1527.             Case "UID"
  1528.               gsODBCUserName = Mid(sTmp, InStr(1, sTmp, "=") + 1, Len(sTmp))
  1529.             Case "PWD"
  1530.               gsODBCPassword = Mid(sTmp, InStr(1, sTmp, "=") + 1, Len(sTmp))
  1531.             Case "Driver"
  1532.               gsODBCDriver = Mid(sTmp, InStr(1, sTmp, "=") + 1, Len(sTmp))
  1533.             Case "Server"
  1534.               gsODBCServer = Mid(sTmp, InStr(1, sTmp, "=") + 1, Len(sTmp))
  1535.              Case Else
  1536.               'nothing
  1537.           End Select
  1538.         End If
  1539.         sTmp = vbNullString
  1540.       Else
  1541.         sTmp = sTmp + Mid(rsConnect, i, 1)
  1542.       End If
  1543.       i = i + 1
  1544.     Wend
  1545.   End If
  1546. End Sub
  1547.  
  1548. '------------------------------------------------------------
  1549. 'this is a generic sub that adds the name of each item
  1550. 'in a collection to the passed in control
  1551. '------------------------------------------------------------
  1552. Sub ListItemNames(rcCollection As Object, rnCtl As Control, bClearList As Integer)
  1553.   On Error GoTo LINErr
  1554.   
  1555.   Dim objTmp As Object
  1556.   Dim i As Integer
  1557.   
  1558.   If bClearList Then
  1559.     rnCtl.Clear
  1560.   End If
  1561.   
  1562.   For Each objTmp In rcCollection
  1563.     rnCtl.AddItem objTmp.Name
  1564.   Next
  1565.  
  1566.   Exit Sub
  1567.   
  1568. LINErr:
  1569.   ShowError
  1570. End Sub
  1571.  
  1572. '------------------------------------------------------------
  1573. 'this sub closes the current DB and performs any cleanup
  1574. 'and resetting of controls, menus, etc.
  1575. '------------------------------------------------------------
  1576. Sub CloseCurrentDB()
  1577.   On Error GoTo DBCloseErr
  1578.  
  1579.   If gdbCurrentDB Is Nothing Then Exit Sub
  1580.     
  1581.   If gbDBChanged Then
  1582.     If MsgBox(MSG32, vbYesNo + vbQuestion) = vbYes Then
  1583.       gwsMainWS.CommitTrans
  1584.       gbDBChanged = False
  1585.     Else
  1586.       If MsgBox(MSG33, vbYesNo + vbQuestion) = vbYes Then
  1587.         gwsMainWS.Rollback
  1588.         gbDBChanged = False
  1589.       Else
  1590.         Beep
  1591.         MsgBox MSG34, 48
  1592.         Exit Sub
  1593.       End If
  1594.     End If
  1595.   End If
  1596.  
  1597.   frmMDI.Caption = "VisData"
  1598.   
  1599.   HideDBTools
  1600.  
  1601.   gbDBOpenFlag = False
  1602.   gbTransPending = False
  1603.   gsDBName = vbNullString
  1604.   gnReadOnly = False
  1605.   
  1606.   gdbCurrentDB.Close
  1607.   Set gdbCurrentDB = Nothing
  1608.   UnloadAllForms
  1609.  
  1610.   Exit Sub
  1611.  
  1612. DBCloseErr:
  1613.   ShowError
  1614. End Sub
  1615.  
  1616. '------------------------------------------------------------
  1617. '------------------------------------------------------------
  1618. Sub OpenLocalDB(bSilent As Boolean)
  1619.   On Error GoTo OpenError
  1620.  
  1621.   Dim sConnect As String
  1622.   Dim sDatabaseName As String
  1623.   Dim dbTemp As Database
  1624.   Dim sTmp As String
  1625.  
  1626.   sDatabaseName = gsDBName
  1627.   
  1628.   If Not bSilent Then
  1629.     Select Case gsDataType
  1630.       Case gsMSACCESS
  1631.         frmMDI.dlgCMD1.Filter = MSG49 & MSG50
  1632.         frmMDI.dlgCMD1.DialogTitle = MSG36
  1633.       Case gsDBASEIII, gsDBASEIV, gsDBASE5
  1634.         frmMDI.dlgCMD1.Filter = "Dbase DBs (*.dbf)|*.dbf" & MSG50
  1635.         frmMDI.dlgCMD1.DialogTitle = MSG37
  1636.       Case gsFOXPRO20, gsFOXPRO25, gsFOXPRO26, gsFOXPRO30
  1637.         frmMDI.dlgCMD1.Filter = "FoxPro DBs (*.dbf)|*.dbf" & MSG50
  1638.         frmMDI.dlgCMD1.DialogTitle = MSG38
  1639.       Case gsPARADOX3X, gsPARADOX4X, gsPARADOX5X
  1640.         frmMDI.dlgCMD1.Filter = "Paradox DBs (*.db)|*.db" & MSG50
  1641.         frmMDI.dlgCMD1.DialogTitle = MSG39
  1642.       Case gsEXCEL50
  1643.         frmMDI.dlgCMD1.Filter = "Excel Files (*.xls)|*.xls" & MSG50
  1644.         frmMDI.dlgCMD1.DialogTitle = MSG40
  1645.       Case gsBTRIEVE
  1646.         frmMDI.dlgCMD1.Filter = "Btrieve DBs (FILE.DDF)|FILE.DDF" & MSG50
  1647.         frmMDI.dlgCMD1.DialogTitle = MSG41
  1648.       Case gsTEXTFILES
  1649.         frmMDI.dlgCMD1.Filter = "Text Files (*.txt)|*.txt" & MSG50
  1650.         frmMDI.dlgCMD1.DialogTitle = MSG42
  1651.     End Select
  1652.  
  1653.     frmMDI.dlgCMD1.FilterIndex = 1
  1654.     frmMDI.dlgCMD1.FileName = gsDBName  '""
  1655.     frmMDI.dlgCMD1.CancelError = True
  1656.     frmMDI.dlgCMD1.Flags = FileOpenConstants.cdlOFNFileMustExist
  1657.     frmMDI.dlgCMD1.ShowOpen
  1658.  
  1659.     If Len(frmMDI.dlgCMD1.FileName) > 0 Then
  1660.       gsDBName = frmMDI.dlgCMD1.FileName
  1661.     Else
  1662.       Exit Sub
  1663.     End If
  1664.   Else
  1665.     gsDBName = sDatabaseName
  1666.   End If
  1667.   
  1668.   If Len(gsDBName) = 0 Then
  1669.     MsgBar vbNullString, False
  1670.     Exit Sub
  1671.   End If
  1672.  
  1673.   MsgBar MSG43, True
  1674.   Screen.MousePointer = vbHourglass
  1675.  
  1676.   'set the connect string
  1677.   If gsDataType = gsMSACCESS Then
  1678.     sConnect = vbNullString
  1679.   Else
  1680.     sConnect = gsDataType
  1681.   End If
  1682.   
  1683.   'set the database name for non Microsoft Access and Btrieve dbs that
  1684.   'came from the Common Dialog
  1685.   If gsDataType <> gsMSACCESS And gsDataType <> gsBTRIEVE And _
  1686.      gsDataType <> gsEXCEL50 And (Not bSilent) Then
  1687.     'need to strip off filename for these dbs
  1688.     sDatabaseName = StripFileName(gsDBName)
  1689.     gsDBName = sDatabaseName
  1690.   Else
  1691.     sDatabaseName = gsDBName
  1692.   End If
  1693.  
  1694.   GoTo OneMoreTry
  1695.   
  1696. GetPWD:
  1697.   Dim frmPWD As New frmDBPWD
  1698.   frmPWD.Show vbModal
  1699.   If Len(frmPWD.PWD) > 0 Then
  1700.     sConnect = ";pwd=" & frmPWD.PWD
  1701.     Unload frmPWD
  1702.     Set frmPWD = Nothing
  1703.     MsgBar MSG43, True
  1704.     Screen.MousePointer = vbHourglass
  1705.   Else
  1706.     'they cancelled the pwd dialog so we need to exit
  1707.     Unload frmPWD
  1708.     Set frmPWD = Nothing
  1709.     Exit Sub
  1710.   End If
  1711.  
  1712. OneMoreTry:
  1713.   If (frmMDI.dlgCMD1.Flags And FileOpenConstants.cdlOFNReadOnly) = FileOpenConstants.cdlOFNReadOnly Then
  1714.     gnReadOnly = True
  1715.   Else
  1716.     gnReadOnly = False
  1717.   End If
  1718.   Set dbTemp = gwsMainWS.OpenDatabase(sDatabaseName, False, gnReadOnly, sConnect)
  1719.   If gbDBOpenFlag Then
  1720.     'save the db name
  1721.     sTmp = gsDBName
  1722.     'restore it
  1723.     CloseCurrentDB
  1724.     gsDBName = sTmp
  1725.     If gbDBOpenFlag Then
  1726.       Beep
  1727.       MsgBox MSG35, 48
  1728.       Exit Sub
  1729.     End If
  1730.   End If
  1731.  
  1732.   'success
  1733.   frmMDI.Caption = "VisData:" & sDatabaseName
  1734.   Set gdbCurrentDB = dbTemp
  1735.   gbDBOpenFlag = True
  1736.   ShowDBTools
  1737.   RefreshTables Nothing
  1738.   gdbCurrentDB.QueryTimeout = glQueryTimeout
  1739.  
  1740.   AddMRU
  1741.   If gsDataType <> gsMSACCESS Then
  1742.     MsgBar MSG44, False
  1743.   End If
  1744.   Screen.MousePointer = vbDefault
  1745.  
  1746.   Exit Sub
  1747.  
  1748. AttemptRepair:
  1749.   Screen.MousePointer = vbHourglass
  1750.   MsgBar MSG45 & gsDBName, True
  1751.   DBEngine.RepairDatabase gsDBName
  1752.   Screen.MousePointer = vbDefault
  1753.   GoTo OneMoreTry
  1754.  
  1755. OpenError:
  1756.   Screen.MousePointer = vbDefault
  1757.   If Err = 3049 Then
  1758.     If MsgBox(Err.Description & vbCrLf & vbCrLf & MSG46, 4 + 48) = vbYes Then
  1759.       Resume AttemptRepair
  1760.     End If
  1761.   ElseIf Err = 3031 Then
  1762.     'password protected database
  1763.     Resume GetPWD
  1764.   End If
  1765.   gbDBOpenFlag = False
  1766.   gsDBName = vbNullString
  1767.   gsDataType = vbNullString
  1768.   gsODBCDatabase = vbNullString
  1769.   gsODBCUserName = vbNullString
  1770.   gsODBCPassword = vbNullString
  1771.   gsODBCDriver = vbNullString
  1772.   gsODBCServer = vbNullString
  1773.   If Err <> 32755 And Err <> 3049 Then   'check for common dialog cancelled
  1774.     ShowError
  1775.   End If
  1776. End Sub
  1777.  
  1778. '------------------------------------------------------------
  1779. 'this sub is used to create a new directory for one
  1780. 'of the local ISAM data types
  1781. '------------------------------------------------------------
  1782. Sub NewLocalISAM()
  1783.    On Error GoTo NewISAMErr
  1784.  
  1785.    Dim sNewName As String
  1786.    Dim d As Database
  1787.  
  1788. GetNewDirName:
  1789.    sNewName = InputBox(MSG47, , sNewName)
  1790.    If Len(sNewName) = 0 Then Exit Sub
  1791.  
  1792.    If Mid(sNewName, Len(sNewName), 1) <> "\" Then sNewName = sNewName & "\"
  1793.  
  1794.    MkDir Mid(sNewName, 1, Len(sNewName) - 1)
  1795.  
  1796.    gsDBName = sNewName
  1797.    OpenLocalDB True
  1798.  
  1799.    If gbDBOpenFlag Then
  1800.      ShowDBTools
  1801.      RefreshTables Nothing
  1802.    End If
  1803.  
  1804.   Exit Sub
  1805.  
  1806. NewISAMErr:
  1807.   If Err = 75 Then Resume Next  'catch the case where dir exists
  1808.   If Err = 76 Then
  1809.     MsgBox MSG65, vbExclamation
  1810.     'now try again
  1811.     Resume GetNewDirName
  1812.   End If
  1813.   ShowError
  1814. End Sub
  1815.  
  1816. '------------------------------------------------------------
  1817. 'this sub is called from the compact menu options
  1818. 'on the main MDI form
  1819. '------------------------------------------------------------
  1820. Sub CompactDB(rnCompactVersion As Integer)
  1821.   On Error GoTo CompactAccErr
  1822.  
  1823.   Dim sOldName As String
  1824.   Dim sNewName As String
  1825.   Dim sNewName2 As String
  1826.   Dim nEncrypt As Integer
  1827.  
  1828.   'get file name to compact
  1829.   frmMDI.dlgCMD1.Filter = MSG49
  1830.   frmMDI.dlgCMD1.DialogTitle = MSG48
  1831.   frmMDI.dlgCMD1.FilterIndex = 1
  1832.   frmMDI.dlgCMD1.Flags = FileOpenConstants.cdlOFNHideReadOnly
  1833.   frmMDI.dlgCMD1.ShowOpen
  1834.   If Len(frmMDI.dlgCMD1.FileName) > 0 Then
  1835.     sOldName = frmMDI.dlgCMD1.FileName
  1836.   Else
  1837.     Exit Sub
  1838.   End If
  1839.  
  1840.   'get file name to compact to
  1841.   frmMDI.dlgCMD1.DialogTitle = MSG51
  1842.   frmMDI.dlgCMD1.FilterIndex = 1
  1843.   frmMDI.dlgCMD1.FileName = vbNullString
  1844.   frmMDI.dlgCMD1.CancelError = True
  1845.   frmMDI.dlgCMD1.Flags = FileOpenConstants.cdlOFNOverwritePrompt + FileOpenConstants.cdlOFNHideReadOnly
  1846.   frmMDI.dlgCMD1.ShowSave
  1847.   If Len(frmMDI.dlgCMD1.FileName) > 0 Then
  1848.     sNewName = frmMDI.dlgCMD1.FileName
  1849.     If Dir(sNewName) <> vbNullString And sOldName <> sNewName Then
  1850.       Kill sNewName
  1851.     End If
  1852.   Else
  1853.     Exit Sub
  1854.   End If
  1855.  
  1856.   If MsgBox(MSG52, vbYesNo + vbQuestion) = vbYes Then
  1857.     nEncrypt = dbEncrypt
  1858.   Else
  1859.     nEncrypt = dbDecrypt
  1860.   End If
  1861.  
  1862.   Screen.MousePointer = vbHourglass
  1863.   MsgBar MSG53 & sOldName & " -> " & sNewName, True
  1864.   'if they want to overwrite the same file, we need to create a new MDB
  1865.   'and rename after the compact is successful
  1866.   If sOldName = sNewName Then
  1867.     sNewName2 = sNewName 'save the new name
  1868.     sNewName = Left(sNewName, Len(sNewName) - 1) & "N"
  1869.   End If
  1870.   
  1871.   DBEngine.CompactDatabase sOldName, sNewName, dbLangGeneral, rnCompactVersion + nEncrypt
  1872.   
  1873.   'check for an overwrite of the original mdb
  1874.   If VBA.Right(sNewName, 1) = "N" Then
  1875.     Kill sNewName2             'nuke the old one
  1876.     Name sNewName As sNewName2 'rename the new one to the original name
  1877.     sNewName = sNewName2       'reset to the correct name
  1878.   End If
  1879.   
  1880.   MsgBar vbNullString, False
  1881.   Screen.MousePointer = vbDefault
  1882.  
  1883.   If MsgBox(MSG54, vbYesNo + vbQuestion) = vbYes Then
  1884.     If gbDBOpenFlag Then
  1885.       CloseCurrentDB
  1886.     End If
  1887.     gsDataType = gsMSACCESS
  1888.     gsDBName = sNewName
  1889.     OpenLocalDB True
  1890.   End If
  1891.  
  1892.   If gbDBOpenFlag Then
  1893.     ShowDBTools
  1894.     RefreshTables Nothing
  1895.   End If
  1896.  
  1897.   Exit Sub
  1898.  
  1899. CompactAccErr:
  1900.   If Err <> 32755 Then         'user cancelled
  1901.     ShowError
  1902.   End If
  1903. End Sub
  1904.  
  1905. '------------------------------------------------------------
  1906. 'this sub does some cleanup and shuts down VisData
  1907. '------------------------------------------------------------
  1908. Sub ShutDownVisData()
  1909.   On Error Resume Next
  1910.  
  1911.   Dim nRet As Integer
  1912.  
  1913.   'save all the current INI file settings
  1914.   SaveINISettings
  1915.  
  1916.   If gbDBChanged Then
  1917.     If MsgBox(MSG32, vbYesNo + vbQuestion) = vbYes Then
  1918.       gwsMainWS.CommitTrans
  1919.     End If
  1920.   End If
  1921.  
  1922.   UnloadAllForms
  1923.   gdbCurrentDB.Close
  1924.   'close the help file
  1925.   nRet = OSWinHelp(frmMDI.hwnd, App.HelpFile, HelpConstants.cdlHelpQuit, 0)
  1926.   
  1927.   End
  1928.  
  1929. End Sub
  1930. Sub NewMDB(rnVersion As Integer)
  1931.   On Error GoTo NewAccErr
  1932.  
  1933.   Dim sNewName As String
  1934.   Dim db As Database
  1935.  
  1936.   'get file name to compact to
  1937.   frmMDI.dlgCMD1.DialogTitle = MSG55
  1938.   frmMDI.dlgCMD1.FilterIndex = 1
  1939.   frmMDI.dlgCMD1.Filter = MSG49
  1940.   frmMDI.dlgCMD1.FileName = vbNullString
  1941.   frmMDI.dlgCMD1.CancelError = True
  1942.   frmMDI.dlgCMD1.Flags = FileOpenConstants.cdlOFNOverwritePrompt + FileOpenConstants.cdlOFNHideReadOnly
  1943.   frmMDI.dlgCMD1.ShowSave
  1944.   If Len(frmMDI.dlgCMD1.FileName) > 0 Then
  1945.     sNewName = frmMDI.dlgCMD1.FileName
  1946.     If InStr(sNewName, ".") = 0 Then
  1947.       'add an extension if the user didn't supply one
  1948.       sNewName = sNewName & ".MDB"
  1949.     End If
  1950.     If Dir(sNewName) <> vbNullString Then
  1951.       Kill sNewName
  1952.     End If
  1953.   Else
  1954.     Exit Sub
  1955.   End If
  1956.   If Len(sNewName) = 0 Then Exit Sub
  1957.  
  1958.   Set db = CreateDatabase(sNewName, dbLangGeneral, rnVersion)
  1959.   db.Close
  1960.  
  1961.   gsDataType = gsMSACCESS
  1962.   gsDBName = sNewName
  1963.   OpenLocalDB True
  1964.   Exit Sub
  1965.  
  1966. NewAccErr:
  1967.   If Err <> 32755 Then         'user cancelled
  1968.     ShowError
  1969.   End If
  1970. End Sub
  1971.  
  1972. Sub Export(rsFromTbl As String, rsToDB As String)
  1973.  
  1974.   On Error GoTo ExpErr
  1975.  
  1976.   Dim sConnect As String
  1977.   Dim sNewTblName As String
  1978.   Dim sDBName As String
  1979.   Dim nErrState As Integer
  1980.   Dim idxFrom As Index
  1981.   Dim idxTo As Index
  1982.   Dim sSQL As String              'local copy of sql string
  1983.   Dim sField As String
  1984.   Dim sFrom As String
  1985.   Dim sTmp As String
  1986.   Dim i As Integer
  1987.  
  1988.   If gnDataType = gnDT_SQLDB Then
  1989.     Set gExpDB = gwsMainWS.OpenDatabase(vbNullString, 0, 0, "odbc;")
  1990.     If gExpDB Is Nothing Then Exit Sub
  1991.   End If
  1992.  
  1993.   MsgBar MSG56 & "'" & rsFromTbl & "'", True
  1994.  
  1995.   nErrState = 1
  1996.   Select Case gnDataType
  1997.     Case gnDT_MSACCESS
  1998.       sConnect = "[;database=" & rsToDB & "]."
  1999.       Set gExpDB = gwsMainWS.OpenDatabase(rsToDB)
  2000.     Case gnDT_PARADOX3X
  2001.       sDBName = StripFileName(rsToDB)
  2002.       sConnect = "[Paradox 3.X;database=" & StripFileName(rsToDB) & "]."
  2003.       Set gExpDB = gwsMainWS.OpenDatabase(sDBName, 0, 0, gsPARADOX3X)
  2004.     Case gnDT_PARADOX4X
  2005.       sDBName = StripFileName(rsToDB)
  2006.       sConnect = "[Paradox 4.X;database=" & StripFileName(rsToDB) & "]."
  2007.       Set gExpDB = gwsMainWS.OpenDatabase(sDBName, 0, 0, gsPARADOX4X)
  2008.     Case gnDT_FOXPRO26
  2009.       sDBName = StripFileName(rsToDB)
  2010.       sConnect = "[FoxPro 2.6;database=" & StripFileName(rsToDB) & "]."
  2011.       Set gExpDB = gwsMainWS.OpenDatabase(sDBName, 0, 0, gsFOXPRO26)
  2012.     Case gnDT_FOXPRO25
  2013.       sDBName = StripFileName(rsToDB)
  2014.       sConnect = "[FoxPro 2.5;database=" & StripFileName(rsToDB) & "]."
  2015.       Set gExpDB = gwsMainWS.OpenDatabase(sDBName, 0, 0, gsFOXPRO25)
  2016.     Case gnDT_FOXPRO20
  2017.       sDBName = StripFileName(rsToDB)
  2018.       sConnect = "[FoxPro 2.0;database=" & StripFileName(rsToDB) & "]."
  2019.       Set gExpDB = gwsMainWS.OpenDatabase(sDBName, 0, 0, gsFOXPRO20)
  2020.     Case gnDT_DBASEIV
  2021.       sDBName = StripFileName(rsToDB)
  2022.       sConnect = "[dBase IV;database=" & StripFileName(rsToDB) & "]."
  2023.       Set gExpDB = gwsMainWS.OpenDatabase(sDBName, 0, 0, gsDBASEIV)
  2024.     Case gnDT_DBASEIII
  2025.       sDBName = StripFileName(rsToDB)
  2026.       sConnect = "[dBase III;database=" & StripFileName(rsToDB) & "]."
  2027.       Set gExpDB = gwsMainWS.OpenDatabase(sDBName, 0, 0, gsDBASEIII)
  2028.     Case gnDT_BTRIEVE
  2029.       sConnect = "[Btrieve;database=" & rsToDB & "]."
  2030.       Set gExpDB = gwsMainWS.OpenDatabase(rsToDB, 0, 0, gsBTRIEVE)
  2031.     Case gnDT_EXCEL50, gnDT_EXCEL40, gnDT_EXCEL30
  2032.       sConnect = "[Excel 5.0;database=" & rsToDB & "]."
  2033.       Set gExpDB = gwsMainWS.OpenDatabase(rsToDB, 0, 0, gsEXCEL50)
  2034.     Case gnDT_SQLDB
  2035.       sConnect = "[" & gExpDB.Connect & "]."
  2036.     Case gnDT_TEXTFILE
  2037.       sDBName = StripFileName(rsToDB)
  2038.       sConnect = "[Text;database=" & StripFileName(rsToDB) & "]."
  2039.       Set gExpDB = gwsMainWS.OpenDatabase(sDBName, 0, 0, gsTEXTFILES)
  2040.   End Select
  2041.   If gnDataType = gnDT_MSACCESS Or gnDataType = gnDT_BTRIEVE Or _
  2042.      gnDataType = gnDT_SQLDB Or gnDataType = gnDT_EXCEL50 Or _
  2043.      gnDataType = gnDT_EXCEL40 Or gnDataType = gnDT_EXCEL30 Then
  2044.     With frmExpName
  2045.       .Label1.Caption = MSG57 & rsFromTbl & " ->"
  2046.       .Label2.Caption = MSG58 & rsToDB
  2047.       .txtTable.Text = rsFromTbl
  2048.     End With
  2049.     frmExpName.Show vbModal
  2050.       
  2051.     If Len(gExpTable) = 0 Then
  2052.       MsgBar vbNullString, False
  2053.       Exit Sub
  2054.     Else
  2055.       sNewTblName = gExpTable
  2056.     End If
  2057.   Else
  2058.     'get the table part of the file name
  2059.     'strip off the path
  2060.     For i = Len(rsToDB) To 1 Step -1
  2061.       If Mid(rsToDB, i, 1) = "\" Then
  2062.         Exit For
  2063.       End If
  2064.     Next
  2065.     sTmp = Mid(rsToDB, i + 1, Len(rsToDB))
  2066.     'strip off the extension
  2067.     For i = 1 To Len(sTmp)
  2068.       If Mid(sTmp, i, 1) = "." Then
  2069.         Exit For
  2070.       End If
  2071.     Next
  2072.     sNewTblName = Left(sTmp, i - 1)
  2073.   End If
  2074.   Screen.MousePointer = vbHourglass
  2075.   If Len(rsFromTbl) > 0 Then
  2076.     gdbCurrentDB.Execute "select * into " & sConnect & StripOwner(sNewTblName) & " from " & StripOwner(rsFromTbl)
  2077.  
  2078.     If gnDataType <> gnDT_TEXTFILE Then
  2079.       nErrState = 2
  2080.       MsgBar MSG59 & " '" & sNewTblName & "'", True
  2081.       gExpDB.TableDefs.Refresh
  2082.       For Each idxFrom In gdbCurrentDB.TableDefs(rsFromTbl).Indexes
  2083.         Set idxTo = gExpDB.TableDefs(sNewTblName).CreateIndex(idxFrom.Name)
  2084.         With idxTo
  2085.           .Fields = idxFrom.Fields
  2086.           .Unique = idxFrom.Unique
  2087.           If gnDataType <> gnDT_SQLDB And gsDataType <> "ODBC" Then
  2088.             .Primary = idxFrom.Primary
  2089.           End If
  2090.         End With
  2091.         gExpDB.TableDefs(sNewTblName).Indexes.Append idxTo
  2092.       Next
  2093.     End If
  2094.     MsgBar vbNullString, False
  2095.     Screen.MousePointer = vbDefault
  2096.     MsgBox MSG60 & " '" & rsFromTbl & "'", 64
  2097.   Else
  2098.     sSQL = frmSQL.txtSQLStatement.Text
  2099.     sField = Mid(sSQL, 8, InStr(8, UCase(sSQL), "FROM") - 9)
  2100.     sFrom = " " & Mid(sSQL, InStr(UCase(sSQL), "FROM"), Len(sSQL))
  2101.     gdbCurrentDB.Execute "select " & sField & " into " & sConnect & sNewTblName & sFrom
  2102.  
  2103.     Screen.MousePointer = vbDefault
  2104.     MsgBar vbNullString, False
  2105.     MsgBox MSG61, 64
  2106.   End If
  2107.  
  2108.   Exit Sub
  2109.  
  2110. ExpErr:
  2111.   If Err = 3010 Then      'table exists
  2112.     If MsgBox(MSG62, 32 + 1 + 256) = 1 Then
  2113.       gExpDB.TableDefs.Delete sNewTblName
  2114.       Resume
  2115.     Else
  2116.       Screen.MousePointer = vbDefault
  2117.       MsgBar vbNullString, False
  2118.       Exit Sub
  2119.     End If
  2120.   End If
  2121.  
  2122.   'nuke the new table if the indexes couldn't be created
  2123.   If nErrState = 2 Then
  2124.     gExpDB.TableDefs.Delete sNewTblName
  2125.   End If
  2126.   ShowError
  2127. End Sub
  2128.  
  2129. Sub Import(rsImpTblName As String)
  2130.   On Error GoTo ImpErr
  2131.  
  2132.   Dim sOldTblName As String, sNewTblName As String, sConnect As String
  2133.   Dim idxFrom As Index
  2134.   Dim idxTo As Index
  2135.   Dim nErrState As Integer
  2136.   Dim i As Integer
  2137.  
  2138.   sOldTblName = MakeTableName(rsImpTblName, False)
  2139.   sNewTblName = MakeTableName(rsImpTblName, True)
  2140.  
  2141.   Screen.MousePointer = vbHourglass
  2142.   MsgBar MSG63 & "'" & sNewTblName & "'", True
  2143.  
  2144.   nErrState = 1
  2145.   Select Case gnDataType
  2146.     Case gnDT_MSACCESS
  2147.       sConnect = "[;database=" & gImpDB.Name & "]."
  2148.     Case gnDT_PARADOX3X
  2149.       sConnect = "[Paradox 3.X;database=" & StripFileName(rsImpTblName) & "]."
  2150.       Set gImpDB = gwsMainWS.OpenDatabase(StripFileName(rsImpTblName), 0, 0, gsPARADOX3X)
  2151.     Case gnDT_PARADOX4X
  2152.       sConnect = "[Paradox 4.X;database=" & StripFileName(rsImpTblName) & "]."
  2153.       Set gImpDB = gwsMainWS.OpenDatabase(StripFileName(rsImpTblName), 0, 0, gsPARADOX4X)
  2154.     Case gnDT_FOXPRO26
  2155.       sConnect = "[FoxPro 2.6;database=" & StripFileName(rsImpTblName) & "]."
  2156.       Set gImpDB = gwsMainWS.OpenDatabase(StripFileName(rsImpTblName), 0, 0, gsFOXPRO26)
  2157.     Case gnDT_FOXPRO25
  2158.       sConnect = "[FoxPro 2.5;database=" & StripFileName(rsImpTblName) & "]."
  2159.       Set gImpDB = gwsMainWS.OpenDatabase(StripFileName(rsImpTblName), 0, 0, gsFOXPRO25)
  2160.     Case gnDT_FOXPRO20
  2161.       sConnect = "[FoxPro 2.0;database=" & StripFileName(rsImpTblName) & "]."
  2162.       Set gImpDB = gwsMainWS.OpenDatabase(StripFileName(rsImpTblName), 0, 0, gsFOXPRO20)
  2163.     Case gnDT_DBASEIV
  2164.       sConnect = "[dBase IV;database=" & StripFileName(rsImpTblName) & "]."
  2165.       Set gImpDB = gwsMainWS.OpenDatabase(StripFileName(rsImpTblName), 0, 0, gsDBASEIV)
  2166.     Case gnDT_DBASEIII
  2167.       sConnect = "[dBase III;database=" & StripFileName(rsImpTblName) & "]."
  2168.       Set gImpDB = gwsMainWS.OpenDatabase(StripFileName(rsImpTblName), 0, 0, gsDBASEIII)
  2169.     Case gnDT_BTRIEVE
  2170.       sConnect = "[Btrieve;database=" & gImpDB.Name & "]."
  2171.     Case gnDT_EXCEL50, gnDT_EXCEL40, gnDT_EXCEL30
  2172.       sConnect = "[Excel 5.0;database=" & gImpDB.Name & "]."
  2173.     Case gnDT_SQLDB
  2174.       sConnect = "[" & gImpDB.Connect & "]."
  2175.     Case gnDT_TEXTFILE
  2176.       sConnect = "[Text;database=" & StripFileName(rsImpTblName) & "]."
  2177.       Set gImpDB = gwsMainWS.OpenDatabase(StripFileName(rsImpTblName), 0, 0, gsTEXTFILES)
  2178.   End Select
  2179.   gdbCurrentDB.Execute "select * into " & sNewTblName & " from " & sConnect & sOldTblName
  2180.  
  2181.   If gnDataType <> gnDT_TEXTFILE And gnDataType <> gnDT_EXCEL50 And _
  2182.      gnDataType <> gnDT_EXCEL40 And gnDataType <> gnDT_EXCEL30 Then
  2183.     nErrState = 2
  2184.     MsgBar gdbCurrentDB.RecordsAffected & " Rows Imported, Creating Indexes for '" & sNewTblName & "'", True
  2185.     gdbCurrentDB.TableDefs.Refresh
  2186.     For Each idxFrom In gImpDB.TableDefs(sOldTblName).Indexes
  2187.       Set idxTo = gdbCurrentDB.TableDefs(sNewTblName).CreateIndex(idxFrom.Name)
  2188.       With idxTo
  2189.         .Fields = idxFrom.Fields
  2190.         .Unique = idxFrom.Unique
  2191.         If gnDataType <> gnDT_SQLDB And gsDataType <> gsSQLDB Then
  2192.           .Primary = idxFrom.Primary
  2193.         End If
  2194.       End With
  2195.       gdbCurrentDB.TableDefs(sNewTblName).Indexes.Append idxTo
  2196.     Next
  2197.   End If
  2198.     
  2199.   frmImpExp.lstTables.AddItem sNewTblName
  2200. '  frmTables.lstTables.AddItem sNewTblName
  2201.   Screen.MousePointer = vbDefault
  2202.   MsgBar vbNullString, False
  2203.   MsgBox MSG64 & "'" & sNewTblName & "'.", 64
  2204.  
  2205.   Exit Sub
  2206.  
  2207. NukeNewTbl:
  2208.   On Error Resume Next  'just in case it fails
  2209.   gdbCurrentDB.TableDefs.Delete sNewTblName
  2210.   ShowError
  2211.   Exit Sub
  2212.  
  2213. ImpErr:
  2214.   'nuke the new table if the indexes couldn't be created
  2215.   If nErrState = 2 Then
  2216.     Resume NukeNewTbl
  2217.   End If
  2218.   ShowError
  2219. End Sub
  2220.  
  2221. Function MakeTableName(fname As String, newname As Integer) As String
  2222.   On Error Resume Next
  2223.   Dim i As Integer, t As Integer
  2224.   Dim tmp As String
  2225.  
  2226.   If gnDataType = gnDT_SQLDB And newname Then
  2227.     i = InStr(1, fname, ".")
  2228.     If i > 0 Then
  2229.       tmp = Mid(fname, 1, i - 1) & "_" & Mid(fname, i + 1, Len(fname))
  2230.     End If
  2231.   ElseIf InStr(fname, "\") > 0 Then
  2232.     'strip off path
  2233.     For i = Len(fname) To 1 Step -1
  2234.       If Mid(fname, i, 1) = "\" Then
  2235.         Exit For
  2236.       End If
  2237.     Next
  2238.     tmp = Mid(fname, i + 1, Len(fname))
  2239.     i = InStr(1, tmp, ".")
  2240.     If i > 0 Then
  2241.       tmp = Mid(tmp, 1, i - 1)
  2242.     End If
  2243.   Else
  2244.     tmp = fname
  2245.   End If
  2246.  
  2247.   If newname Then
  2248.     If DupeTableName(tmp) Then
  2249.       t = 1
  2250.       While DupeTableName(tmp + CStr(t))
  2251.         t = t + 1
  2252.       Wend
  2253.       tmp = tmp + CStr(t)
  2254.     End If
  2255.   End If
  2256.  
  2257.   MakeTableName = tmp
  2258.  
  2259. End Function
  2260.  
  2261.  
  2262.