Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 7th, 2015, 01:10 PM
Registered User
 
Join Date: Feb 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert table to different form using vba mkhanna Excel VBA 3 June 25th, 2010 04:58 AM
delete a user form using vba sms Access VBA 2 June 27th, 2008 07:15 AM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM
VBA - Form Refresh lxu Access 2 March 4th, 2004 11:13 AM
VBA - Form refresh lxu XML 2 March 3rd, 2004 01:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.