Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Attribute VB_Name = "TestDataObject"
- Option Compare Database
- Option Explicit
- Public Sub Run()
- On Error GoTo Catch
- Dim PDO As DataObject, Results As Object, Item As Variant, _
- RoleName As String, ModuleName As String
- DoCmd.SetWarnings False
- ModuleName = VBE.ActiveCodePane.CodeModule.Name
- Application.SetOption "ANSI Query Mode", True
- DoCmd.RunSQL "CREATE TABLE tblRole (" & _
- "RoleId AUTOINCREMENT(1, 1) CONSTRAINT PrimaryKey PRIMARY KEY, " & _
- "RoleName VARCHAR NOT NULL, " & _
- "Description VARCHAR, " & _
- "CONSTRAINT RoleNamekey UNIQUE (RoleName))"
- ' tblErrorLog
- ' Id|3010|A következõ tábla már létezik: 'tblRole'.|Sub Run|TestDataObject
- ' NOW|Environ$("USERNAME")|Environ$("COMPUTERNAME")
- Set PDO = New DataObject
- With PDO
- .Query = "INSERT INTO tblRole (RoleName) VALUES (:RoleName)"
- RoleName = CStr(Timer)
- .Bind ":RoleName", RoleName
- .Bind ":RoleName", RoleName & RoleName
- ' tblErrorLog
- ' Id|-2147220991|Parameter exists [:RoleName]|Sub Bind|DataObject
- ' NOW|Environ$("USERNAME")|Environ$("COMPUTERNAME")
- .BeginTransaction
- .Execute
- If CBool(.AffectedRows) Then
- Debug.Assert (1 = .AffectedRows)
- .CommitTransaction
- Else
- .RollbackTransaction
- End If
- .Query = "SELECT r.RoleName FROM tblRole r WHERE r.RoleName = :RoleName"
- .Bind ":Rolename", RoleName
- Set Results = .ResultSet
- If CBool(.RecordCount) Then _
- Debug.Assert (RoleName = Results("RoleName"))
- .Query = "SELECT r.RoleName FROM tblRole r WHERE r.RoleId > :RoleId"
- .Bind ":RoleId", 1
- Set Results = .ResultSet
- If Not CBool(.RecordCount) Then GoTo Finally
- For Each Item In Results
- Debug.Print Results(Item)("RoleName")
- DoEvents
- Next Item
- End With
- GoTo Finally
- Catch:
- Handle Err.Number, Err.Description, "", "Sub Run", ModuleName
- Resume Next
- Finally:
- ModuleName = ""
- Set PDO = Nothing
- Set Results = Nothing
- Application.SetOption "ANSI Query Mode", False
- DoCmd.SetWarnings True
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement