03. september 2009 - 10:50Der er
6 kommentarer og 1 løsning
Formular synkronisering
Hej derude. Jeg er stødt på en ny forhindring i min opbygning af en Access database, jeg håber I kan hjælpe.
Jeg har en hovedformular hvopå de fleste felter til min overordnede tabel er placeret. For overskuelighedens skyld har jeg så en række mindre formularer som hver i sær åbnes med en knap. Felterne refererer til indhold i samme tabel.
Det fungerer også fint så længe jeg indtaster data i hovedformularen, gemmer og derefter åbner en underformular og indtaster data.
Men hvis jeg ikke gemmer før jeg åbner en underformular har den underformular ikke fået en reference til den aktuelle post og data som indtastes gemmes ikke sammen med posten. Det er lidt irriterende for den som skal indtaste data, at alting skal gemmes manuelt først, hver gang der skal indtastes i en underformular.
Kan jeg ikke få den til at gøre det automatisk når der klikkes på knappen til underformularen, eller når den åbnes eller andet?
Jeg håber I forstår spørgsmålet med den kringlede beskrivelse, ellers må i lige spørge.
Try placing this line of code BEFORE the line which opens the sub form
RunCommand acCmdSaveRecord
Synes godt om
Slettet bruger
03. september 2009 - 11:40#2
Looks like I need something else too, I'll have to tjek some more, but it seems like when closing the sub form it still does not save the data, cos when opening it again the fields are empty.
To control that the data match the post I use a criteria like this:
If you are updating data on th emain form then normally I would expect the chnages to be saved when you press a button to open a sub form.
If you change data on a sub form and want to show these changes on the main form then you need to requery the main form BEFORE you close the sub form (FORMS!NameOfMainForm.Requery)
Synes godt om
Slettet bruger
03. september 2009 - 17:34#4
Well, I try to explain more detailed.
The mainform is open with some fields. I type the data in those fields and works fine so far, it saves automatically if I change post or close the database. Then I have some sub forms for additional information, called with buttons on the main form. The fields in these sub forms are ofcause empty.
Now I type data in those sub form fields (all fields are from the same table) and close the subform again. If I then reopen the same subform the fields has become empty again. Somehow it does not save the new data.
The workaround I can use, but which is not very usable, is first type data in the main form, then clik one post forward or backward or close and reopen the mainform - and first after that open the subform and type data in it's fields. Then it works as supposed.
So what I need is to make that sub form save the data on close down too, without having to close the main form first or go forward/backword in posts.
But maby the problem is of another type - there might be errors in my coding causing this (I don't get any errormessages though)
To me it sounds as though the record in the main form isnt getting written to the dB before the sub form gets opened.
So you must write the record in the main form using the line of code I gave, before you open the sub form.
If you cant get it working can you send me your dB so I can take a look? ekspertenATsanthell.dk
AT = @
Synes godt om
Slettet bruger
04. september 2009 - 13:16#6
Hi Terry.
Thanks a lot for your help, it seems like I got it right now. I guess I only got it ½ right the first time.
Now my code regarding this looks like this:
RunCommand acCmdSaveRecord Dim stDocName As String Dim stLinkCriteria As String stDocName = "Andet"
But later I have this line to make sure it's the same post: stLinkCriteria = "[Personnummer]=" & "'" & Me![Personnummer] & "'"
So, when I tested the first time I did not get to "Personnummer" field which is one of the bottom filds, before opening the subform. I think that was the reason that the data from the subform wasn,t saved.
It seems to work now, so thanks again for your help!
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.