Avatar billede skov_p Praktikant
07. maj 2002 - 14:49 Der er 8 kommentarer og
1 løsning

Retuner en værdi

Jeg har en komboboks med nogle addesser. Skrives der i komboboksen og addressen ikke findes i forvejen åbnes der en form hvor man kan indtaste forskellige data. Jeg vil gerne vide hvordan jeg finder ud af om brugeren har trykket OK eller cancel efter indtastningen. Lige som man kan med en messagebox.
Avatar billede terry Ekspert
07. maj 2002 - 14:58 #1
If you are trying to decide IF the data was actually accepted then somthing like this will do
DoCmd.OpenForm "frmYourForm", , , , acFormAdd, acDialog, NewData
If DLookup("SomeField", "SomeTable", "SomeField = '" & NewData & "'") Then
       
            Response = acDataErrAdded
End If

This will automatically update the combo with new data!
Avatar billede skov_p Praktikant
07. maj 2002 - 15:06 #2
Yes something like that. But what does the response do? does it return a value to the previous form. If yes how do i receive it?
Avatar billede terry Ekspert
07. maj 2002 - 15:11 #3
It tells access that new data was added and to update the combo.

You would have the code in the NOT IN LIST event for the combo.

Dim prompt As String
   
    Response = acDataErrContinue
   
    prompt = "The item was NOT inlist." & vbCrLf
    prompt = prompt & "Do you want to add item?"
DoCmd.OpenForm "frmYourForm", , , , acFormAdd, acDialog, NewData
If DLookup("SomeField", "SomeTable", "SomeField = '" & NewData & "'") Then
       
            Response = acDataErrAdded
End If
Avatar billede skov_p Praktikant
07. maj 2002 - 15:15 #4
I will try to rephrase the question. I have 2 forms. In form 1 you can pick a customer in a combobox. If you enter a customer that doesent exist form 2 will open and you can enter all data about the mew customer. if the user press OK i want to receive OK in form 1 and if he press cancel i want to receive error
Avatar billede terry Ekspert
07. maj 2002 - 15:26 #5
I DO understand that you want to do something IF the user pressed OK and something else IF the user pressed cancel!

IF you are NOT interested in updating the combo with the new data then you will have to set a GLOBAL variable which you can test the value of when form 2 gets closed.

The code I gave UPDATES the combo with the new data IF the user did actually enter the data, but it sounds as though you are not interested in doing that!
Avatar billede skov_p Praktikant
07. maj 2002 - 15:39 #6
Im not sure what the newdata thing is, its empty all the time. acDataErrAdded is 2 on OK and on Cancel. so i dident receive any thing. Im just thinking about making a list count before and after form 2 then i will be able to see if there have been added some thing. But i still would like to know how to call a procedure and send/receive data while doing that.
Avatar billede terry Ekspert
07. maj 2002 - 15:46 #7
in a module you have a variable name (for example)

Public gOK As Boolean

Then in the On click event for the OK button you set this to true

gOK = True

and in the on click event for the Cancel button

gOK = false

then in form 1 you can use this value

If gOK Then
...
Else
...
End if
Avatar billede skov_p Praktikant
07. maj 2002 - 15:56 #8
Is a modul some kind of global variable.
Avatar billede terry Ekspert
07. maj 2002 - 15:57 #9
No a module is a place for storing functions and variables.
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