SQL in form on Access2013 using VBA
This is my first time posting anywhere. I am a newbie Access2013/VBA programmer trying to write my first application.
I have a table T03 with three fields below
T03-ID-Service-Or-Event-Type autonumber
T03-Description-Short text
T03-Description-Long text
I can display a combo box with all three fields on each line.
I want to refer to all three fields from the one line user selected so I can refer/use them everywhere in my application.
With the code below I get error as follows:
" runtime error '-2147217900 (80040e14)' Syntax error in FROM clause'
A friend told me I can't use SQL inside a form.
/code
Private Sub Combo01_Change()
Dim str_SQL_Get_Service_Type As String
Set g_cn = New ADODB.Connection
g_cn.Open "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = Counting.accdb"
MsgBox Combo01.Value ' this does display the 1st field of line selected
Set g_rs_T03 = New ADODB.Recordset
g_rs_T03.ActiveConnection = CurrentProject.Connection
str_SQL_Get_Service_Type = "SELECT * FROM T03_Service_Or_Event_Types WHERE T03_ID_Service_Or_Event_Type = Combo01.Value"
g_rs_T03.Open str_SQL_Get_Service_Type, g_cn, adOpenStatic, adLockOptimistic, adCmdTable
g_rs_T03.Close
End Sub
/code
What am I doing wrong. I hope this is all clearly stated.
Ric
|