type mismatch

T

tessa1278

Hi
I am having problems when submitting values from two combo-boxes in a
form.
I am a novice to programming in access and I would be grateful for any
help that I can get on this problem...

Here is a subtraction of the code that I use:

Dim ArtikkelNavn As String
Dim ValgtEnhet As String
Dim ValgtKategori As String
Dim SQLstrg As String
Dim ValgtKategoriId As Integer
Dim ValgtEnhetsId As Integer

ArtikkelNavn = Me!NyttArtikkelnavn.Value
ValgtEnhet = Me!VelgEnhet.Column(1)
ValgtKategori = Me!VelgKategori.Column(1)

ValgtKategoriId = "Select ID_KAT from T_KATEGORI where
ValgtKategori = T_KATEGORI.KAT_NAVN;"
ValgtEnhetsId = "Select ID_ENHET from T_ENHETER where ValgtEnhet =
T_ENHETER.Enhetsnavn;"


SQLstrg = "INSERT INTO T_ARTIKKEL (NAVN, ID_ENHET, ID_KAT) VALUES
(ArtikkelNavn, ValgtEnhetsId, ValgtKategoriId)"

CurrentDb.Execute SQLstrg, dbFailOnError

therese
 
D

Douglas J Steele

You need to have the values that are in the variables in the SQL, not the
names of the variables. SQL queries know nothing about variables.


ValgtKategoriId = "Select ID_KAT from T_KATEGORI " & _
"where T_KATEGORI.KAT_NAVN=" & ValgtKategori
ValgtEnhetsId = "Select ID_ENHET from T_ENHETER " & _
"where T_ENHETER.Enhetsnavn=" & ValgtEnhet

This assumes that KAT_NAVN and Enhetsnavn are both numeric fields. If
they're text, you need to include quotes:

ValgtKategoriId = "Select ID_KAT from T_KATEGORI " & _
"where T_KATEGORI.KAT_NAVN=" & Chr$(34) & ValgtKategori & Chr$(34)
ValgtEnhetsId = "Select ID_ENHET from T_ENHETER " & _
"where T_ENHETER.Enhetsnavn=" & Chr$(34) & ValgtEnhet & Chr$(34)
 
Top