Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus batch bios bsod crash desktop driver drivers error ethernet excel freeze gaming gpu hard drive hardware hdmi internet laptop malware memory monitor motherboard netgear network printer problem ram registry router server slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Syntax Integer Variable in VBA SQL

Reply  
Thread Tools
jmorlan's Avatar
Junior Member with 2 posts.
 
Join Date: Sep 2010
04-Sep-2010, 07:27 PM #1
Post Solved: Syntax Integer Variable in VBA SQL
I am using Access 2010-

I have a sql statement that has two variables to set the rowsource for a combo box

This is what I have-

Code:
Private Sub Form_Load()
'Form Name Information
Dim strFormName As String
strFormName = Me.Form.Name
'Form Number Information
Dim IntFormNumber As Long
IntFormNumber = DLookup("[frm_nmbr]", "Tbl_FormManager", "[frm_name] = '" & strFormName & "'")
MsgBox strFormName & "" & IntFormNumber ' Used to make sure I was getting the correct information back
'ComboBox RowSource Information
Dim FormCtrl As Control
Dim strCtrlName As String
Dim intCtrlNumber As Long
Dim strSQL As String
For Each FormCtrl In Me.Controls
If TypeName(FormCtrl) = "ComboBox" Then
strCtrlName = FormCtrl.Name
intCtrlNumber = DLookup("[ctrl_nmbr]", "Tbl_ControlManager", "[ctrl_name]='" & strCtrlName & "'")
MsgBox strCtrlName & "" & intCtrlNumber ' Used to make sure I was getting the correct information back
strSQL = "SELECT Tbl_DropDownManager.fld_value, Tbl_DropDownManager.fld_text, Tbl_BringItTogether.frm_nmbr, Tbl_BringItTogether.ctrl_nmbr, Tbl_BringItTogether.fld_pos FROM Tbl_BringItTogether INNER JOIN Tbl_DropDownManager ON Tbl_BringItTogether.fld_val = Tbl_DropDownManager.fld_value WHERE Tbl_BringItTogether.frm_nmbr = '" & IntFormNumber & "' And Tbl_BringItTogether.ctrl_nmbr = '" & intCtrlNumber & "'  ORDER BY Tbl_BringItTogether.fld_pos;"
FormCtrl.RowSource = strSQL
End If
Next
End Sub
I keep getting a data mismatch error when I click on the combo box. I think it has something to do with the quotation's and apostrophe's around the Variable names (Highlighted with Red Text), but I can't find how I should do it.

I think this is really simple I just have been trying to figure it out for a while that is has become really frustrating.
Zack Barresse's Avatar
Computer Specs
Distinguished Member with 5,030 posts.
 
Join Date: Jul 2004
Location: Oregon, United States
Experience: I'ma learnin'!
04-Sep-2010, 09:34 PM #2
If you're trying to pass a number, you shouldn't need any qualifiers surrounding it. You may already know this, but here's some good info on these things:

http://www.fontstuff.com/access/acctut15.htm#5mincourse

HTH
Ziggy1's Avatar
Computer Specs
Senior Member with 2,450 posts.
 
Join Date: Jun 2002
Location: Ontario,Canada
Experience: Advanced
06-Sep-2010, 03:01 PM #3
Access 2010, so hard to keep current, I have 2007.... anyways. have you tried removing the single quotes around the number types? in the SQL?

I removed them and changed the sql arrangement slightly to make it more readable....


Code:
strSQL = "SELECT Tbl_DropDownManager.fld_value, Tbl_DropDownManager.fld_text, Tbl_BringItTogether.frm_nmbr, Tbl_BringItTogether.ctrl_nmbr, Tbl_BringItTogether.fld_pos "
strSQL = strSQL + "FROM Tbl_BringItTogether INNER JOIN Tbl_DropDownManager ON Tbl_BringItTogether.fld_val = Tbl_DropDownManager.fld_value "
strSQL = strSQL + "WHERE Tbl_BringItTogether.frm_nmbr = " & IntFormNumber & " And Tbl_BringItTogether.ctrl_nmbr = " & intCtrlNumber & "  "
strSQL = strSQL + "ORDER BY Tbl_BringItTogether.fld_pos;"

I recommend you use the "Imediate" window to debug the sql string, along with break points..... or when it errors:

put this in the immediate window....

?strSQL then hit enter Then you can see the SQL better than trying to use a message box
__________________
Ziggy

ô¿ô

Last edited by Ziggy1; 06-Sep-2010 at 03:16 PM..
jmorlan's Avatar
Junior Member with 2 posts.
 
Join Date: Sep 2010
06-Sep-2010, 09:24 PM #4
Syntax Integer Variable in VBA SQL
Ziggy1,

I copied your code into my database to start working with the cleaned up version and well I guess you solved my problem, it works fine now.

I am not totally for sure how, but I will put your code example in my reference database for future use.
Appreciate the help!!!!

Thanks,

Jay
Zack Barresse's Avatar
Computer Specs
Distinguished Member with 5,030 posts.
 
Join Date: Jul 2004
Location: Oregon, United States
Experience: I'ma learnin'!
06-Sep-2010, 09:36 PM #5
Quote:
Originally Posted by jmorlan View Post
I am not totally for sure how...
Did you read the thread I posted? It tells you how, or rather why, the solution works.
Ziggy1's Avatar
Computer Specs
Senior Member with 2,450 posts.
 
Join Date: Jun 2002
Location: Ontario,Canada
Experience: Advanced
06-Sep-2010, 10:24 PM #6
that was actually a good link Zack.


Jay its easy to get lost in the VBA when doing the SQL, especially when quotes are involved.... so be sure to test with the immediate window.

Another trick you can do is copy the output from the immediate window and paste it into a SQL view of the query design grid.... then switch to design view or sheet view to check your output (may not work in every scenario).... this helps you troubleshoot.
__________________
Ziggy

ô¿ô
Reply

Tags
sql, syntax, variable

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools


Similar Threads
Title Thread Starter Forum Replies Last Post
Solved: Multiple variables in address bar - PHP r3drock3t88 Web Design & Development 2 12-Jul-2009 01:45 PM
Solved: Declaring Global Variables in Access 2007 SimonB Business Applications 7 02-Oct-2008 09:22 AM
Declaring and Using Global Variables in Access VBA SimonB Business Applications 0 07-Aug-2008 11:32 AM
Solved: problem with apostrophe in vba sql insert into cmd piamik2 Business Applications 11 29-Aug-2007 10:25 AM
Expandable Variables in VBA goels Software Development 1 01-Oct-2004 03:59 PM


Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:43 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.