Avatar billede norway Nybegynder
14. oktober 2008 - 08:42 Der er 6 kommentarer og
1 løsning

Oppdatering av flere felt i record ved "Not In List"

Jeg trenger å gå til riktig record etter å ha oppdatert en komboboks med et nytt record.
I koden under så opprette jeg et nytt firma, men når jeg så skal legge til adressen i en tekstboks så kommer denne på neste record og ikke i det jeg akkurat opprettet.
Firmanavn kommer i record 1 og Adresse i record 2.
Jeg ønsker at Firma kommer i record 1 felt 1 og adresse  i record 1 felt 2.


Private Sub Company_NotInList(NewData As String, Response As Integer)
Response = acDataErrContinue

If MsgBox("Firma" & NewData & " er ikke i listen. Vil du legge til?", vbYesNo, "Firma mangler!") = vbYes Then
Dim db As Database
Dim rstCompany As Recordset
Dim sqlCompany As String
Set db = CurrentDb()
sqlCompany = "Select * From Company"
Set rstCompany = db.OpenRecordset(sqlCompany, dbOpenDynaset)
rstCompany.AddNew
rstCompany![Company] = NewData
rstCompany.Update
Response = acDataErrAdded
rstCompany.Close
End If
End Sub
Avatar billede terry Ekspert
14. oktober 2008 - 09:55 #1
Not sure I quiet understand your explanantion, but I'll try and explain what I think you could do.

You need a form for entering the new "firma". Then in your NotInList event you need to open the form in dialog mode to allow the user to enter all required fields. If you include NewData in the OpenArgs paramater in the DoCmd.OpenForm .... you can put the NewData (now in OpenArgs) into the appropriate field.

Then when you close the form it woul dbe an idea to use DCount to make sure that the actual record was added before setting Response = acDataErrAdded
Avatar billede norway Nybegynder
14. oktober 2008 - 10:23 #2
It's almost like that except that the form is already open, in case that the company already exist in the combobox. But if it's not exist I need to add it and filling in the other fields in the (already open) form. Do you have any sugestion to how I can do that?
Im a newbie so I need the explanation i code examples, if its not to inconvenience for you? THANX
Avatar billede terry Ekspert
14. oktober 2008 - 11:05 #3
This is the way I see it. If you try choosing a company from the list which deosnt exist then at this point you havent entered any other data for the company in the form, you have only entered a name (for example) in the combo. So when the NotInList event fires where do you get the other fields from?

So you have a couple of choices.
First you can just use the NotInList event to inform the user with a message box that the company doesnt exist in the list and then allow him/her to enter it in the fields on the form. Then update the combo to show the new record.

Or you can open another form in your NotInList event where you enter the other fields as suggested previously.

If I havent understood you correctly can you try and explain in more detail please?
Avatar billede norway Nybegynder
14. oktober 2008 - 14:01 #4
The solution with information to the user with a message seems to be an OK solution, but how do I do that, when the combo is the only place where I can add the new company name? Im using textboxes for the other information as adresses and so on.
Avatar billede terry Ekspert
14. oktober 2008 - 14:49 #5
is it possible for you to send me your dB or an exmaple with the parts I need to see?
ekspertenATsanthell.dk

AT = @

I'll take a look later when I get home from work
Avatar billede norway Nybegynder
14. oktober 2008 - 15:07 #6
Sending an example
Avatar billede terry Ekspert
22. oktober 2008 - 18:01 #7
thanks
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