29. oktober 2002 - 12:29Der er
6 kommentarer og 1 løsning
Tabledefs, rettigheder og currentdb....
Hej Jeg har et problem med tilføjelse af et felt til en database. Min kode ser således ud:
BeginTrans Dim tdf As TableDef Dim dbs As Database Set dbs = CurrentDb() Set tdf = dbs.TableDefs("tSysSkema")
tdf.Fields.Append tdf.CreateField(NewField, dbText, 50) dbs.Close Set tdf = Nothing Set dbs = Nothing CommitTrans
Mit program stopper allerede ved Set dbs = currentdb() Her er meddelelsen:
Du har ikke de nødvendige tilladelser til at bruge objektet "E:\db\booking.mdb". Få systemadministratoren eller den person, der oprettede dette objekt, til at give dig de nødvendige tilladelser.
Databasen er sikret, men jeg er i administratorgruppen.
I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
Here ís an example of using transactions and your code doesnt seem right!
One or more table pages remain locked while the user decides whether or not to accept the changes. Consequently, this technique isn't recommended but is shown only as an example.
Sub ChangeTitle() Dim wsp As Workspace, dbs As Database, rst As Recordset Dim strName As String, strMessage As String, strPrompt As String Dim fInTrans As Boolean
On Error GoTo ChangeTitleErr
fInTrans = False strPrompt = "Change title to Account Executive?" ' Return reference to default Workspace object. Set wsp = DBEngine.Workspaces(0) ' Return reference to current database. Set dbs = CurrentDb ' Create table-type Recordset object. Set rst = dbs.OpenRecordset("Employees", dbOpenTable)
' Start of transaction. wsp.BeginTrans fInTrans = True rst.MoveFirst Do Until rst.EOF If rst!Title = "Sales Representative" Then strName = rst!LastName & ", " & rst!FirstName strMessage = "Employee: " & strName & vbCrLf & vbCrLf If MsgBox(strMessage & strPrompt, vbQuestion + vbYesNo, _ "Change Job Title") = vbYes Then ' Enable editing. rst.Edit rst!Title = "Account Executive" ' Save changes.
rst.Update End If End If ' Move to next record. rst.MoveNext Loop If MsgBox("Save all changes?", vbQuestion + vbYesNo, _ " Save Changes") = vbYes Then wsp.CommitTrans ' Commit changes. Else wsp.Rollback ' Undo changes. End If ChangeTitleExit: rst.Close Set dbs = Nothing Set wsp = Nothing Exit Sub ChangeTitleErr: MsgBox "Error!" If fInTrans Then wsp.Rollback End If
is it a bad idea to use transactions in this case?
Anyway, I tried to remove the lines and then it worked... I am a bit worried that I might get the error later on again, because i am pretty sure that I also tested it without transactions. I hope that it is ok that I follow up on this tread if that should happpen. But for now, it works. Thanks Torben
I cant see it necessary to use a transaction here! If you add a field to a table then no-one is using that field (they cant, it doesnt exist) so adding a field and then implementing th euse of it later is no problem.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.