13. marts 2006 - 17:03Der er
8 kommentarer og 2 løsninger
Opret ny post
Hej
Jeg har et mystisk problem. Når jeg afspiller funktion (se længere nede) fra en knap (on klik hændelse) virker det fint men når jeg afspiller samme funktion fra en makro kan jeg i min debug se at det "oprindelige kontaktpersonid ikke fornyes ved acnew og at jeg derfor får duplicate fejl ved inserten. Er der nogen der kan hjælpe mig med en forklaring?
Det lugter af at du kører koden i samme øjeblik, du hopper til den nye post. I så tilfælde er posten stadig i redigeringstilstand og ID'et er derfor ukendt. Posten må gemmes først før koden kan bruge ID'et. Tilføj en Forms!kontaktpersoner.Refresh efter Forms!kontaktpersoner!Firmanavn = Null
Du er i øvrigt meget omhyggelig ;o)
Forms!kontaktpersoner!Firmanavn = " " Forms!kontaktpersoner!Firmanavn = Null En af dem burde være rigeligt.
rs.Edit rs.AddNew Den første er vist ikke nødvendig.
This is just a guess. When you run the code from a button on the form, then its the forms recordset your adding a record to when you use DoCmd.GoToRecord , , acNewRec
when you run the code from a macro then this doesnt know which form we want to add a record to.
But why do you want to use a macro when the button works?
Let me tjeck if I understand you correctly: Instead of having the function declared outside the form ("global programkode"), you think that it will help to move the function to the form.
Im not able to test before tonight but I will let you know of the result many regards from Flemming
Isnt the code you gave in your question in a form, or are you calling the code from the form?
If the code is in a module, then maybe you can still use that, but get the macro to run some code in the form which calls the function in the module.
I'm not sure if this is goin gto help, but I think its worth a try. I have a feeling that its because the macro deosnt know which form we are trying to add a record to.
It may also be enough to set focus on the form (from the macro).
Im sure you are right Terry but I cant get it to work just by moving the function to the form. I have been looking for some code to activate the button on the form, but I haven't been lucky so far. I think I will give up. The environment acts apperently different when running code from a makro when we are speeking of recordsets belonging to a form and it is a luxurious problem I have here: I will let the customer keep on using the button at the form.
Thanks for the comments and the help to both of you.
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.