Avatar billede piphans Nybegynder
30. august 2002 - 08:50 Der 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

    Else
        Response = acDataErrContinue

    End If
   
End Sub

---------------------------------------------------

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?
Avatar billede nih Novice
30. august 2002 - 09:03 #1
me.combo.requery

til sidst i din kode
Avatar billede piphans Nybegynder
30. august 2002 - 09:20 #2
nih

Det virker ikke. Nu får jeg denne meddelelse.

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,

Øhhh - hvad nu?
Avatar billede terry Ekspert
30. august 2002 - 09:23 #3
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
       
            Response = acDataErrAdded
           
        End If
   
    End If

End Sub
Avatar billede terry Ekspert
30. august 2002 - 09:23 #4
.
Avatar billede terry Ekspert
30. august 2002 - 09:23 #5
The Dlookup just confirms that the data was added.
Avatar billede piphans Nybegynder
30. august 2002 - 09:28 #6
Hej Terry

Jeg forstår ikke dit svar?

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???
Avatar billede terry Ekspert
30. august 2002 - 09:35 #7
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)
Avatar billede piphans Nybegynder
30. august 2002 - 09:40 #8
Terry

OK - now i have removed the line:
ID = InputBox("Indtast personens Initialer", "Tilføj person")

And changed the line:
![Initialer] = ID into
![Initialer] = NewData

But the result is the same. The data is entered into the table, but the combobox is not updated, and the error message is the same
Avatar billede terry Ekspert
30. august 2002 - 09:41 #9
The Limit To List property must be set to True

You can send the dB to me and I will take a look if you like.
dktebrsa@europe.lego.com
Avatar billede nih Novice
30. august 2002 - 09:42 #10
Jeg får samme fejl som piphans, og har ingen løsning lige nu :(
Avatar billede terry Ekspert
30. august 2002 - 09:44 #11
well perhaps I can help you too Niels :o)
Avatar billede nih Novice
30. august 2002 - 09:45 #12
I hope so :o)
Avatar billede piphans Nybegynder
30. august 2002 - 09:53 #13
Thanks Terry, I really appreciate that - but where can i find your email address?
Avatar billede terry Ekspert
30. august 2002 - 09:55 #14
Look at the comment 09:41:15
Avatar billede piphans Nybegynder
30. august 2002 - 09:57 #15
hi hi sorry!!!
I'm so confused....
Avatar billede terry Ekspert
30. august 2002 - 10:55 #16
problem was response spelt incorrectly!

responce
Avatar billede piphans Nybegynder
30. august 2002 - 11:00 #17
Pinligt men sandt!

1000 tak til Terry!
Avatar billede nih Novice
30. august 2002 - 11:04 #18
Argh    :o)
Avatar billede mhq Nybegynder
03. november 2003 - 22:18 #19
Hi Terry

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?
Avatar billede terry Ekspert
03. november 2003 - 22:28 #20
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)
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