14. oktober 2008 - 08:42Der 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
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
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
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?
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.
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.