home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap28 / frm128.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-10-11  |  15.4 KB  |  439 lines

  1. VERSION 4.00
  2. Begin VB.Form form128 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   5940
  6.    ClientLeft      =   1140
  7.    ClientTop       =   1515
  8.    ClientWidth     =   6690
  9.    Height          =   6375
  10.    Left            =   1080
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5940
  13.    ScaleWidth      =   6690
  14.    Top             =   1140
  15.    Width           =   6810
  16.    Begin VB.CommandButton cmdcreatetable 
  17.       Caption         =   "Create Table"
  18.       Height          =   390
  19.       Left            =   1920
  20.       TabIndex        =   16
  21.       Top             =   2400
  22.       Width           =   1635
  23.    End
  24.    Begin VB.CommandButton cmdrecordsets 
  25.       Caption         =   "RecordSet Examples"
  26.       Height          =   390
  27.       Left            =   180
  28.       TabIndex        =   15
  29.       Top             =   2400
  30.       Width           =   1635
  31.    End
  32.    Begin VB.CommandButton cmdqryopenrecordset 
  33.       Caption         =   "Open Recordset Qry"
  34.       Height          =   390
  35.       Left            =   3660
  36.       TabIndex        =   14
  37.       Top             =   2880
  38.       Width           =   1635
  39.    End
  40.    Begin VB.CommandButton cmdqueryexecute 
  41.       Caption         =   "Query execute"
  42.       Height          =   390
  43.       Left            =   1920
  44.       TabIndex        =   13
  45.       Top             =   2880
  46.       Width           =   1635
  47.    End
  48.    Begin VB.CommandButton cmdtdopenrecordset 
  49.       Caption         =   "Open Recordsets TD"
  50.       Height          =   390
  51.       Left            =   180
  52.       TabIndex        =   12
  53.       Top             =   2880
  54.       Width           =   1635
  55.    End
  56.    Begin VB.CommandButton cmdcreatetdproperty 
  57.       Caption         =   "Create Property TD"
  58.       Height          =   390
  59.       Left            =   3660
  60.       TabIndex        =   11
  61.       Top             =   3360
  62.       Width           =   1635
  63.    End
  64.    Begin VB.CommandButton cmcreateindex 
  65.       Caption         =   "Create Index"
  66.       Height          =   390
  67.       Left            =   1920
  68.       TabIndex        =   10
  69.       Top             =   3360
  70.       Width           =   1635
  71.    End
  72.    Begin VB.CommandButton cmdaddfield 
  73.       Caption         =   "Add field"
  74.       Height          =   390
  75.       Left            =   180
  76.       TabIndex        =   9
  77.       Top             =   3360
  78.       Width           =   1635
  79.    End
  80.    Begin VB.CommandButton cmdrelation 
  81.       Caption         =   "Create Relation"
  82.       Height          =   390
  83.       Left            =   3660
  84.       TabIndex        =   8
  85.       Top             =   3840
  86.       Width           =   1635
  87.    End
  88.    Begin VB.CommandButton cmdquery 
  89.       Caption         =   "Create Query"
  90.       Height          =   390
  91.       Left            =   1920
  92.       TabIndex        =   7
  93.       Top             =   3840
  94.       Width           =   1635
  95.    End
  96.    Begin VB.CommandButton cmdcreateproperty 
  97.       Caption         =   "Create Property DB"
  98.       Height          =   390
  99.       Left            =   180
  100.       TabIndex        =   6
  101.       Top             =   3840
  102.       Width           =   1635
  103.    End
  104.    Begin VB.CommandButton cmdrecordset 
  105.       Caption         =   "Open Recordsets"
  106.       Height          =   390
  107.       Left            =   3660
  108.       TabIndex        =   5
  109.       Top             =   4320
  110.       Width           =   1635
  111.    End
  112.    Begin VB.CommandButton cmdversion 
  113.       Caption         =   "Version "
  114.       Height          =   390
  115.       Left            =   1920
  116.       TabIndex        =   4
  117.       Top             =   4320
  118.       Width           =   1635
  119.    End
  120.    Begin VB.CommandButton cmdeditable 
  121.       Caption         =   "Editable Record"
  122.       Height          =   390
  123.       Left            =   180
  124.       TabIndex        =   3
  125.       Top             =   4320
  126.       Width           =   1635
  127.    End
  128.    Begin VB.CommandButton cmdrecordeffected 
  129.       Caption         =   "Records Effected"
  130.       Height          =   390
  131.       Left            =   3660
  132.       TabIndex        =   2
  133.       Top             =   4800
  134.       Width           =   1635
  135.    End
  136.    Begin VB.CommandButton cmdcreate 
  137.       Caption         =   "Create DataBase"
  138.       Height          =   390
  139.       Left            =   1920
  140.       TabIndex        =   1
  141.       Top             =   4800
  142.       Width           =   1635
  143.    End
  144.    Begin VB.CommandButton cmdtransactions 
  145.       Caption         =   "Transaction Example"
  146.       Height          =   390
  147.       Left            =   180
  148.       TabIndex        =   0
  149.       Top             =   4800
  150.       Width           =   1635
  151.    End
  152. Attribute VB_Name = "form128"
  153. Attribute VB_Creatable = False
  154. Attribute VB_Exposed = False
  155. Option Explicit
  156. Private Sub cmcreateindex_Click()
  157. Dim wstitle As Workspace
  158. Dim dbbiblio As Database
  159. Dim indx1 As index
  160. Dim fld1 As Field
  161. Dim tbltitles As TableDef
  162. ' Create the WorkSpace
  163. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  164. ' Open the DataBase
  165. Set dbbiblio = wstitle.OpenDatabase("\source\chap28\biblio.mdb", False, False)
  166. ' Open the Table Definition
  167. Set tbltitles = dbbiblio!titles
  168. ' Create the new Index object.
  169. Set indx1 = tbltitles.CreateIndex("nonthindx")
  170. ' define the index field
  171. Set fld1 = indx1.CreateField("month")
  172. ' Define the index as non primary, non unique, and non required
  173. indx1.Unique = False
  174. indx1.Primary = False
  175. indx1.Required = False
  176. indx1.Fields.Append fld1 ' Save Index definition by appending it to Indexes collection.
  177. tbltitles.Indexes.Append indx1
  178. End Sub
  179. Private Sub cmdaddfield_Click()
  180. Dim wstitle As Workspace
  181. Dim dbbiblio As Database
  182. Dim tbltitles As TableDef
  183. Dim fld1 As Field
  184. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  185. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  186. ' Get the Existing Table Definition
  187. Set tbltitles = dbbiblio!titles
  188. ' Create Field object.
  189. Set fld1 = tbltitles.CreateField("month", dbText, 12)
  190.     ' Append MyField to Fields collection.
  191. tbltitles.Fields.Append fld1
  192. End Sub
  193. Private Sub cmdcreate_Click()
  194. Dim wstitle As Workspace
  195. Dim dbnew As Database
  196. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  197. Set dbnew = wstitle.CreateDatabase("\source\chap28\new.mdb", dbLangGeneral)
  198. End Sub
  199. Private Sub cmdcreateproperty_Click()
  200. Dim wstitle As Workspace
  201. Dim dbbiblio As Database
  202. Dim propdirty As Property
  203. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  204. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  205. ' Create the New Property
  206. Set propdirty = dbbiblio.CreateProperty("dirty", dbBoolean, True, False)
  207. ' Save the Property definition
  208. dbbiblio.Properties.Append propdirty
  209. Debug.Print propdirty.Value
  210. propdirty.Value = True
  211. Debug.Print propdirty.Value
  212. End Sub
  213. Private Sub cmdcreatetable_Click()
  214. Dim wstitle As Workspace
  215. Dim dbbiblio As Database
  216. Dim newtable As TableDef
  217. Dim fld1 As Field
  218. Dim fld2 As Field
  219. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  220. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  221. ' creates a table if Data Base specified in Parameter 1
  222. Set newtable = dbbiblio.CreateTableDef("books")
  223. ' add the fields to the tabledef Object
  224. Set fld1 = newtable.CreateField("")
  225. fld1.Name = "Title"
  226. fld1.Type = dbText
  227. fld1.Size = 30
  228. newtable.Fields.Append fld1
  229. Set fld2 = newtable.CreateField("")
  230. fld2.Name = "Author"
  231. fld2.Type = dbText
  232. fld2.Size = 30
  233. newtable.Fields.Append fld2
  234. ' Now add the table definition to the database object
  235. ' ---------------------------------------------
  236. dbbiblio.TableDefs.Append newtable
  237. End Sub
  238. Private Sub cmdcreatetdproperty_Click()
  239. Dim wstitle As Workspace
  240. Dim dbbiblio As Database
  241. Dim proptext As Property
  242. Dim tbltitle As TableDef
  243. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  244. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  245. Set tbltitle = dbbiblio!titles
  246. ' Create the New Property
  247. Set proptext = tbltitle.CreateProperty("contents", dbText, "Test", False)
  248. ' Save the Property definition
  249. tbltitle.Properties.Append proptext
  250. Debug.Print proptext.Value
  251. proptext.Value = " testing property"
  252. Debug.Print proptext.Value
  253. End Sub
  254. Private Sub cmdeditable_Click()
  255. Dim wstitle As Workspace
  256. Dim dbbiblio As Database
  257. Dim rstitles As Recordset
  258. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  259. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, True)
  260. Set rstitles = dbbiblio.OpenRecordset(" select * from titles", dbOpenDynaset)
  261. If dbbiblio.Updatable = True Then
  262.     rstitles.Edit
  263.     MsgBox ("This Recordset Is Read Only ")
  264. End If
  265. End Sub
  266. Private Sub cmdqryopenrecordset_Click()
  267. Dim wstitle As Workspace
  268. Dim dbbiblio As Database
  269. Dim proptext As Property
  270. Dim tbltitle As TableDef
  271. Dim qrynew As QueryDef
  272. Dim rstitle As Recordset
  273. ' open the Workspace
  274. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  275. ' open the DataBase
  276. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  277. ' Set the QueryDef  Definition
  278. Set qrynew = dbbiblio.OpenQueryDef("new")
  279. qrynew.SQL = " Select * from titles "
  280. ' Open the RecordSet
  281. Set rstitle = qrynew.OpenRecordset(dbOpenDynaset)
  282. End Sub
  283. Private Sub cmdquery_Click()
  284. Dim wstitle As Workspace
  285. Dim dbbiblio As Database
  286. Dim qrynew As QueryDef
  287. Dim rstitles As Recordset
  288. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  289. Set dbbiblio = wstitle.OpenDatabase("\source\chap28\biblio.mdb", False, False)
  290. ' Create a New QueryDef
  291. Set qrynew = dbbiblio.CreateQueryDef("new", "Select * from titles where pubid = 13")
  292. ' Load The Recordset based on the New Query
  293. Set rstitles = dbbiblio.OpenRecordset("new", dbOpenDynaset)
  294. End Sub
  295. Private Sub cmdqueryexecute_Click()
  296. Dim wstitle As Workspace
  297. Dim dbbiblio As Database
  298. Dim qrynew As QueryDef
  299. Dim rstitles As Recordset
  300. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  301. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  302. Set rstitles = dbbiblio.OpenRecordset(" select * from titles", dbOpenDynaset)
  303. Set qrynew = dbbiblio.OpenQueryDef("new")
  304. qrynew.SQL = "update titles set notes = 'Test Notes'"
  305. wstitle.BeginTrans
  306. qrynew.Execute
  307. If MsgBox("There have been " & qrynew.RecordsAffected & " Records changed Do you wish to Save the Changes you have Made ", vbYesNo, "", "", 0) = vbYes Then
  308.     wstitle.CommitTrans
  309.     wstitle.Rollback
  310. End If
  311. End Sub
  312. Private Sub cmdrecordeffected_Click()
  313. Dim wstitle As Workspace
  314. Dim dbbiblio As Database
  315. Dim rstitles As Recordset
  316. Dim csql As String
  317. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  318. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  319. Set rstitles = dbbiblio.OpenRecordset(" select * from titles", dbOpenDynaset)
  320. wstitle.BeginTrans
  321. csql = " update titles set notes = 'Test Notes' "
  322. dbbiblio.Execute csql, dbFailOnError
  323. If MsgBox("There have been " & dbbiblio.RecordsAffected & " Records changed Do you wish to Save the Changes you have Made ", vbYesNo, "", "", 0) = vbYes Then
  324.     wstitle.CommitTrans
  325.     wstitle.Rollback
  326. End If
  327. End Sub
  328. Private Sub cmdrecordset_Click()
  329. Dim wstitle As Workspace
  330. Dim dbbiblio As Database
  331. Dim rstitles As Recordset
  332. Dim dstitles As Dynaset
  333. Dim sntitles As Snapshot
  334. Dim tbltitles As Table
  335. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  336. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, True)
  337. ' old method to create a Dynaset Object
  338. Set dstitles = dbbiblio.CreateDynaset("Select * from titles")
  339. 'New Method to Open a Dynaset Type Recordset
  340. Set rstitles = dbbiblio.OpenRecordset(" select * from titles", dbOpenDynaset)
  341. ' old method to create a Table Object
  342. Set tbltitles = dbbiblio.OpenTable("titles")
  343. 'New Method to Open a Dynaset Type Recordset
  344. Set rstitles = dbbiblio.OpenRecordset("titles", dbOpenTable)
  345. ' Old method to create a SnapShot Object
  346. Set sntitles = dbbiblio.CreateSnapshot("Select * from titles")
  347. 'New Method to Open a Dynaset Type Recordset
  348. Set rstitles = dbbiblio.OpenRecordset(" select * from titles", dbOpenSnapshot)
  349. End Sub
  350. Private Sub cmdrecordsets_Click()
  351. Dim wstitle As Workspace
  352. Dim dbbiblio As Database
  353. Dim rstitles As Recordset
  354. Dim dstitles As Dynaset
  355. Dim sntitles As Snapshot
  356. Dim tbltitles As Table
  357. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  358. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, True)
  359. ' old method to create a Dynaset Object
  360. 'Set dstitles = dbbiblio.CreateDynaset("Select * from titles")
  361. 'New Method to Open a Dynaset Type Recordset
  362. Set rstitles = dbbiblio.OpenRecordset(" select * from titles", dbOpenDynaset)
  363. ' old method to create a Table Object
  364. 'Set tbltitles = dbbiblio.OpenTable("titles")
  365. 'New Method to Open a Dynaset Type Recordset
  366. 'Set rstitles = dbbiblio.OpenRecordset("titles", dbOpenTable)
  367. ' Old method to create a SnapShot Object
  368. 'Set sntitles = dbbiblio.CreateSnapshot("Select * from titles")
  369. 'New Method to Open a Dynaset Type Recordset
  370. 'Set rstitles = dbbiblio.OpenRecordset(" select * from titles", dbOpenSnapshot)
  371. rstitles.AbsolutePosition = 1
  372. End Sub
  373. Private Sub cmdrelation_Click()
  374. Dim wstitle As Workspace
  375. Dim dbbiblio As Database
  376. Dim relnew As Relation
  377. Dim fld1 As Field
  378. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  379. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  380. ' Create a New Relation
  381. Set relnew = dbbiblio.CreateRelation("new", "publishers", "titles", _
  382. dbRelationLeft + dbRelationUpdateCascade + dbRelationDeleteCascade)
  383. ' Set the parant table field for the Relation
  384. Set fld1 = relnew.CreateField("pubid")
  385. ' Set the Child Table field for the Relation
  386. fld1.ForeignName = "pubid"
  387. ' Update the Fields portion of the Relations Collection
  388. relnew.Fields.Append fld1
  389. ' Update the New Relation to the  Relations Collection
  390. dbbiblio.Relations.Append relnew
  391. End Sub
  392. Private Sub cmdtdopenrecordset_Click()
  393. Dim wstitle As Workspace
  394. Dim dbbiblio As Database
  395. Dim proptext As Property
  396. Dim tbltitle As TableDef
  397. Dim rstitle As Recordset
  398. ' open the Workspace
  399. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  400. ' open the DataBase
  401. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  402. ' Set the Table Definition
  403. Set tbltitle = dbbiblio!titles
  404. ' Open the RecordSet
  405. Set rstitle = tbltitle.OpenRecordset(dbOpenDynaset)
  406. End Sub
  407. Private Sub cmdtransactions_Click()
  408. Dim wstitle As Workspace
  409. Dim dbbiblio As Database
  410. Dim rstitles As Recordset
  411. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  412. Set dbbiblio = wstitle.OpenDatabase("biblio.mdb", False, False)
  413. Set rstitles = dbbiblio.OpenRecordset(" select * from titles", dbOpenDynaset)
  414. If rstitles.RecordCount = 0 Then
  415.     Exit Sub
  416. End If
  417. wstitle.BeginTrans
  418. Do While rstitles.EOF = False
  419.     rstitles.Edit
  420.     rstitles("notes") = " Test Notes "
  421.     rstitles.Update
  422.     rstitles.MoveNext
  423. If MsgBox("Do you wish to Save the Changes you have Made ", vbYesNo, "", "", 0) = vbYes Then
  424.     wstitle.CommitTrans
  425.     wstitle.Rollback
  426. End If
  427. End Sub
  428. Private Sub cmdversion_Click()
  429. Dim wstitle As Workspace
  430. Dim dbbiblio As Database
  431. Dim rstitles As Recordset
  432. Set wstitle = DBEngine.CreateWorkspace("title", "Admin", "")
  433. Set dbbiblio = wstitle.OpenDatabase("\source\chap28\biblio.mdb", False, True)
  434. MsgBox " The Version of the DBENGINE is " _
  435. & DBEngine.Version & ". The version of the " _
  436. & dbbiblio.Name & " Database is " _
  437. & dbbiblio.Version & "."
  438. End Sub
  439.