08. oktober 2003 - 11:48Der er
5 kommentarer og 1 løsning
SELECT en variabel ud til at teste på
Kan nogen hjælpe en absolut nybegynder i Access her. ? Jeg har en formular i Access med en bagvedliggende kode. Jeg vil gerne indsætte en record i en tabel og det går fint. Dog vil jeg inden lige checke om recorden allerede findes, og vil således selecte for at checke. Min SQL2 er insertkoden, og SQL5 er min check-select. Min nybegynderkode i uddrag ser nogenlunde således ud :
Dim dummy As String dummy = "0" SQL5 = "Select 1 into '&dummy&' from el where telefon = " & f2 & "" DoCmd.RunSQL SQL5 If dummy = "0" Then DoCmd.RunSQL SQL2 End If
....men dummy bliver ved med at være 0, og bliver aldrig 1.
Er godt klar over at det sikkert er noget med mine "plinger" "&" osv. der ikke er syntax-korrekt; men har nogen et bud. Hvordan skriver man variabel-navnet dummy ind. Tror at Access tror at det blot er en tekststreng?
No, I only need to create the record if it doesn't exists, and then later have another formular to popup with the record. (that's another scope, and it works) I'll try the Dcount, and will be back Thanks Poul-Erik
Dim SQL2 As String Dim SQL3 As String Dim SQL4 As String Dim f1 As String Dim f2 As String Dim f3 As String Dim f4 As String Dim dummy As String
dummy = "0" f2 = Form_Relevantekunder.telefon f1 = Form_Relevantekunder.bpnr f3 = Format(Date, "yyyymmdd") f4 = "El" SQL3 = "Values(" & "'" & f1 & "'" & "," & "'" & f2 & "'" & "," & "'" & f3 & "'" & ")" SQL2 = "INSERT INTO el(bpnr, telefon, dato)" & SQL3 SQL4 = "Telefon = " & f2 & "" If DCount("*", "El", "telefon = " & f2) = 0 Then DoCmd.RunSQL SQL2 End If DoCmd.OpenForm "El", , , SQL4 End Sub
...and I only needed to check for existence before calling the new formular, and didn't want to create the record again. I will need more help later for sure, and will be back. I seem to have a problem to get the first formular reselected on return from the second. This is my first Access-application,.....and my first question in this forum, and I have to see how I can pay you the points
If telephone i stext then it has to be inside '' if its a number then not! I can see in your insert that f2 is inside '' so I am assumimg that it is text.
I see your point Terry..... But it IS a number-field, and it works.....don't know why. (It shouldn't..) My other problem with reselection on return is solved too, by using Requery ...and going to currentRecord DoCmd.GoToRecord acDataForm, "el", acGoTo, currrec
This Forum helps a lot. Just searching the questions for a problem, and others have had the same problem, and got the help needed.....often from you Terry, thanks !! My greatest problem is to be familiar with the syntax here in Access. I'm used to ORACLE-SQL, and there is a difference for sure
Poul-Erik
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.