Avatar billede dm013 Nybegynder
09. juni 2003 - 19:46 Der er 25 kommentarer og
1 løsning

Problem med ADP

Hej Eksperter,

jeg har et problem med access frontend op mod MS SQL server.

Når jeg indtaster data i min formular  eksekveres følgende kode(Eksempel):
Private Sub Ftid_AfterUpdate()
On Error GoTo err_Ftid_AfterUpdate
DoCmd.RunCommand acCmdSaveRecord
Call gem_Bdata(BrugerLogin, Desktop, Bnr) 'Modul Gemmer
exit_Ftid_AfterUpdate:
Exit Sub
err_Ftid_AfterUpdate:
Call Report_Error(BrugerLogin, Desktop)
Resume exit_Ftid_AfterUpdate
End Sub
*****************
Function gem_Bdata(BrugerLogin, Desktop, Bnr)
On Error GoTo err_Bdata
        Dim Conn As ADODB.Connection
        Set Conn = CurrentProject.Connection
        Conn.Execute "exec sp_update_user '" & BrugerLogin & "','" & Desktop & "'," & Bnr
        Set Conn = Nothing
exit_Bdata:
Exit Function
err_Bdata:
Call Report_Error(BrugerLogin, Desktop) 'Modul error
Resume exit_Bdata
End Function

Problemet er, at når jeg vil taste en værdi ind i det næste felt får jeg en skrivekonflikt!!!
Hvordan kan jeg løse dette ???
/DM013
Avatar billede dm013 Nybegynder
09. juni 2003 - 19:50 #1
skal lige nævnes at jeg har prøvet at placere:
DoCmd.RunCommand acCmdSaveRecord, mange forskellige steder i et forsøg på at løse dette, også flere gange i det samme modul
Avatar billede terry Ekspert
09. juni 2003 - 19:58 #2
WHY are you trying to save the record in the fields after update event?
Avatar billede terry Ekspert
09. juni 2003 - 19:58 #3
what is it EXACTLY your trying to do?
Avatar billede dm013 Nybegynder
09. juni 2003 - 20:02 #4
i want to know which user last edited the record and from which desktop, therefore i update the user and desktop info  on every field afterupdate.
Avatar billede terry Ekspert
09. juni 2003 - 20:04 #5
Why dont you wait until the records is written (forms after update event) and then Call gem_Bdata(BrugerLogin, Desktop, Bnr) 'Modul Gemmer?
Avatar billede terry Ekspert
09. juni 2003 - 20:06 #6
The record isnt actually written to the dB until the forms AFTER UPDATE is performed so I would wait until AFTER the record is written
Avatar billede dm013 Nybegynder
09. juni 2003 - 20:07 #7
does form_afterupdate apply to the records?
Avatar billede terry Ekspert
09. juni 2003 - 20:07 #8
are you trying to save the record for EVERY field?
Avatar billede terry Ekspert
09. juni 2003 - 20:08 #9
Yes the forms after update event is fired after a NEW record is created OR an existing is altered.
Avatar billede terry Ekspert
09. juni 2003 - 20:08 #10
.
Avatar billede dm013 Nybegynder
09. juni 2003 - 20:11 #11
I'll give it a try and see if that solves my problem :0)

if not I'll get back to you
Avatar billede terry Ekspert
09. juni 2003 - 20:12 #12
OK !
Avatar billede dm013 Nybegynder
09. juni 2003 - 20:46 #13
on the fields_afterupdate i now do nothing,
and on form_afterupdate execute this:
DoCmd.RunCommand acCmdSaveRecord
Call gem_Bdata(BrugerLogin, Desktop, Bnr) 'Modul Gemmer
DoCmd.RunCommand acCmdSaveRecord
**
But i still get the write conflict error !!
Function gem_Bdata(BrugerLogin, Desktop, Bnr)
On Error GoTo err_Bdata
        MsgBox "klar"
        Dim Conn As ADODB.Connection
        Set Conn = CurrentProject.Connection
        Conn.Execute "exec sp_update_user '" & BrugerLogin & "','" & Desktop & "'," & Bnr
        MsgBox "done"
        Set Conn = Nothing
exit_Bdata:
Exit Function
err_Bdata:
Call Report_Error(BrugerLogin, Desktop) 'Modul error
Resume exit_Bdata
End Function
Avatar billede terry Ekspert
09. juni 2003 - 20:48 #14
You should no longer need
DoCmd.RunCommand acCmdSaveRecord
just
Call gem_Bdata(BrugerLogin, Desktop, Bnr)
The record IS saved!
Avatar billede terry Ekspert
09. juni 2003 - 20:50 #15
I am assuming that the form IS bound to the dB!
Avatar billede dm013 Nybegynder
09. juni 2003 - 20:52 #16
Yes, trough an SP and it is the 'unique table' from the Form I am trying to write to in my update call !
Avatar billede terry Ekspert
09. juni 2003 - 20:54 #17
So you should NOT need to use DoCmd.RunCommand acCmdSaveRecord
a record is saved when ALL fields are enterd OR you move to another record.
Avatar billede terry Ekspert
09. juni 2003 - 20:55 #18
Can you jsut explain that please!

Is this
Conn.Execute "exec sp_update_user '" & BrugerLogin & "','" & Desktop & "'," & Bnr

writing to the forms unique table? what are th eother fields on the form?
Avatar billede dm013 Nybegynder
09. juni 2003 - 20:58 #19
The problem is (I think) then I use other SP's to update certain data on the record or transfer data from a linked database to the table(record)
Avatar billede terry Ekspert
09. juni 2003 - 21:02 #20
Not easy when I cant see exactly what your doing! The form should have one "unique" table and thsi data will get written to the dB automatically. If you want to update some other tables you can do this through an SP, but if your trying to update the same record at the same time through an SP then you wil more than likely get problems. Or is it another table?
Avatar billede terry Ekspert
09. juni 2003 - 21:05 #21
if it is the same table then you can change these fields in the forms BEFORE update event!
The record is not yet written to the dB so you can alter other fields jsut before it does get written.
example: If you have a field in the table named BrugerLogin

Me!BrugerLogin = BrugerLogin
Avatar billede dm013 Nybegynder
09. juni 2003 - 21:11 #22
Are you saying that there is no way i can use a SP to update part of my record ?
Avatar billede terry Ekspert
09. juni 2003 - 21:21 #23
WHY is this necessary?

Even so, you should be able to update it with an SP EFTER the record is written to the dB, but then your form is out of sync with the dB! The correct way in my opinion is to do it at the same time as the form gets written and that is by placing values in these fields in the forms BEFORE update event!
Avatar billede terry Ekspert
09. juni 2003 - 21:34 #24
Why do two writes when you can do one :o)
Avatar billede hugopedersen Nybegynder
10. juni 2003 - 07:15 #25
I would have to agrre with Terry (who wouldn't :-) ) - why do something more difficult than needed.
Personaly I do something that looks like what you are trying to do by putting some hidden textboxes on my form and then put some code like the following on the BeforeUpdate event of the form.

Private Sub Form_BeforeUpdate
  If Me.Dirty Then
    Me!txtUser = "Hans Thorsen"
  End If
End Sub
Avatar billede terry Ekspert
10. juni 2003 - 17:47 #26
thanks for your support Hugo :o)
Avatar billede Ny bruger Nybegynder

Din løsning...

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.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester