Avatar billede kimsand Nybegynder
14. marts 2014 - 15:29 Der er 5 kommentarer og
1 løsning

Irriterende inputprompt.

Jeg har noget VBA kode der skal indsætte en post i en DB, linien ser sådan her ud

DoCmd.RunSQL ("Insert into DT_tilbudskalender
(IDtilbudsbeskrivelse, IDrum, IDmedarbejder, dato, dato_gruppestart, starttid, sluttid, antalpladser) Values (Kombinationsboks96.Value, Kombinationsboks129.Value, Kombinationsboks125.Value, fortdato, grupperingsdag, tekst61.Value, tekst63.Value, HoldPladser.Value)")

når denne linie eksekverer, bliver jeg promptet for at skulle indtaste først fortdato og dernæst grupperingsdag.

Begge disse bliver lagt ned i et dato felt der er formatteret som kort datoformat.

variablen fortdato kører i en løkke hvor værdierne er formatteret som kort datoformat, og den ser sådan ud

For fortdato = CDate(Format(Tekst133.Value, shortdate)) To CDate(Format(Tekst135.Value, shortdate))

både fortdato og grupperingsdag er declareret som DATE typer.

Er der mon nogen af jer der ved hvorfor jeg bliver promptet for input ? Jeg har debugget, og der er værdier i begge variablene.

hvis jeg inputter korrekt dato format i prompten, bliver records oprettet korrekt i DB.
Avatar billede terry Ekspert
14. marts 2014 - 17:59 #1
variablen fortdato kører i en løkke hvor værdierne er formatteret som kort datoformat, og den ser sådan ud


"kører i en løkke"???

Is this a variable in code? If so you need to get the value fromthe variable into your SQL

Try

DoCmd.RunSQL ("Insert into DT_tilbudskalender
(IDtilbudsbeskrivelse, IDrum, IDmedarbejder, dato, dato_gruppestart, starttid, sluttid, antalpladser) Values (Kombinationsboks96.Value, Kombinationsboks129.Value, Kombinationsboks125.Value, '" & fortdato "', '" & grupperingsdag & "', tekst61.Value, tekst63.Value, HoldPladser.Value)")
Avatar billede kimsand Nybegynder
14. marts 2014 - 18:25 #2
TY Terry for you response, ive tried your suggestion, and it produces a syntax error 3075 missing operator in query expression "00:00:00", which indicates that it is a time instead of a date...

there is no query in either of those fields in the DB, no relations or anything.

That is weird cause from the table to the code it is declared as date with shortformat.

But 1 thing i dont understand bout your suggestion. The other value entries are bound and unbound values from the form ive created, so why dont i need to make the " & " thing around them ?
Avatar billede kimsand Nybegynder
14. marts 2014 - 18:26 #3
BTW how do you understand Danish when your english :)
Avatar billede kimsand Nybegynder
14. marts 2014 - 18:28 #4
OMG it worked :) TY very much... it was the second variable ive forgotten to give the proper value.
Avatar billede terry Ekspert
15. marts 2014 - 09:28 #5
But 1 thing i dont understand bout your suggestion. The other value entries are bound and unbound values from the form ive created, so why dont i need to make the " & " thing around them ?

If you had done that then I'm sure it would have worked also. Actually that's what I would have done myself as it makes it easier to find errors.

If you have a string variable which you had put the SQL into then you could see the SQL which is being execute in the debug window.

EG:
Dim sSQL as string
sSQL = ("Insert into DT_tilbudskalender
(IDtilbudsbeskrivelse, IDrum, IDmedarbejder, dato, dato_gruppestart, starttid, sluttid, antalpladser) Values (Kombinationsboks96.Value, Kombinationsboks129.Value, Kombinationsboks125.Value, '" & fortdato "', '" & grupperingsdag & "', tekst61.Value, tekst63.Value, HoldPladser.Value)"

DoCmd.RunSQL sSQL



If you had a breakpoint on line
DoCmd.RunSQL sSQL

you could then press CTRL+G to open debug window

then write
?sSQL

you can now see how the variables look in the string. Much easier to see mistakes ...


I've been in DK for over 30 years now so I understand Danish very well, also quiet good a writing too but I still prefer to write in Danish and as most Danes are good at English then generally everyone is happy :-)

And thanks for the points
Avatar billede kimsand Nybegynder
15. marts 2014 - 10:07 #6
TY very much for the explanation, im most certainly happy :)

Im starting off on a big Access journey, and as im constantly getting myself into trouble, these tips of the trade are priceless to me :)
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