30. august 2002 - 08:50Der er
19 kommentarer og 1 løsning
Opdatering af combobox efter ikke på liste
Jeg har en ubundet kombinationsboks der skal hente nogle informationer fra en tabel.
Ved hændelsen "ikke på liste" har jeg lagt følgende kode:
-------------------------------------------
Private Sub Txinit_NotInList(NewData As String, Response As Integer) Dim Navn As String Dim ID As String
responce = acDataErrContinue If MsgBox("den valgte person findes ikke på listen" & vbLf & _ "ønsker du at tilføje den?", vbYesNo, "Ny Person?") = vbYes Then
Navn = InputBox("Instast personens navn", "Tilføj person") ID = InputBox("Indtast personens Initialer", "Tilføj person")
With CurrentDb.TableDefs("TblNavn").OpenRecordset .AddNew ![Initialer] = ID ![Navn] = Navn .Update End With responce = acDataErrAdded
Og koden virker også fint så langt at den opretter en ny post i tabellen TblNavn, men jeg får stadig en fejlmeddelelse om at den tekst jeg indtastede er ikke et element på liste etc.... Og jeg kan ikke se det nye navn i comboboksen.
Hvordan slipper jeg for fejlmeddelelsen, og hvordan gentegner jeg comboboksen så den nye post vises?
Handlingen genforespørg kan ikke afspilles før du gemmer det aktuelle felt @* Hvis du afspiller macroen fra databasevinduet, skal du først gemme feltet og derefter afspille macroen. *Hvis macronavnet er lige med indstillingen af egenskaben beforeUpdate i en visual basic-funktion skal du i stedet angive egenskaben AfterUpdate til macroens navn,
The combo box SHOULD get refeshed automatically WITHOUT Me.combo.requery What puzzles me is that you are NOT adding the NewData to your table and THIS is what youentered in the combo!
Here is an example which I use.
Private Sub cbo_NotInList(NewData As String, Response As Integer) Dim prompt As String
Response = acDataErrContinue
prompt = "Not found in list, do you want to create a new?" If msgBox(prompt, vbYesNo, "Not found!") = vbYes Then
DoCmd.OpenForm "frmLocation", , , , acFormAdd, acDialog, NewData If DLookup("LocationName", "tblLocations", "LocationName = '" & NewData & "'") Then
Der bliver tilføjet nye data til den tabel som comboboksen trækker data fra, for hvis jeg lukker formularen og åbner den igen, så er den nye post med på listen???
When you enter data in the combobox which DOES NOT exist
The Limit To List property must be set to True and the Not In list event must be activated (in use)
The first paramater to the NOT IN LIST event is the data you entered in the combo box.
Here NewData contains what you entered! But from your code I can NOT see that you are actually trying to enter the data in the table! If you areNOT entereing the data in the table.
Private Sub Txinit_NotInList(NewData As String, Response As Integer)
Have used your solution (cf 30/08-2002 09:23:02) quite a lot of times. But this time I cannot make it work!!
Problem is, that the combobox which have to be updated is in a subform. But this conbobox does not get updated the first time the NotInList action is runned, but first at the second time. Why is the ComboBox list not updated the first time?
great to hear people actually do make use of the solutions given on eksperten :o)
I have no idea what the problem can be. Strange that you say it doesnt work on the first NotInList but on the next it does!
I can take a look at it if you send it to me, but it will first be tomorrow after work as I'm off for the evening now.
NOSPANeksperten@santhell.dkNOSPAM
you need to remove NOSPAM
night :o)
Synes godt om
Ny brugerNybegynder
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.