Go Back   DeveloperBarn Forums > Databases > Microsoft Access

Sponsored Links

Discuss "SQL VBA Query" in the Microsoft Access forum.

Microsoft Access - Microsoft Access is a database for small to medium applications. Learn tips and tricks and best database practices here.


Closed Thread « Previous Thread | Next Thread »
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1  
Old May 7th, 2008, 01:25 PM
Barn Newbie
 
Join Date: Apr 2008
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 1
Jaykappy is an unknown quantity at this point
Default SQL VBA Query

Trying to get this query to run but having issues....errors out on the FROM statememt

I am trying to incoporate a variable in the SELECT statement...the variable is actually a field in the table

Thoughts?


Code:
Dim varFieldType As String
varFieldType = Combo85
'MsgBox varFieldType

Dim MySQL As String

'MySQL = "SELECT dbo_Core2.'" & varFieldType & "' FROM dbo_Core2 GROUP BY dbo_Core2.'" & varFieldType & "';"
Sponsored Links
  #2  
Old May 7th, 2008, 01:30 PM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

Remove the single quotes. Because these are actual field names, you don't need them.

Example: the above would output this as the field name in the query: dbo_Core2.'YourFieldName'

Obviously, not what you want
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
  #3  
Old May 7th, 2008, 02:05 PM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 93
Thanks: 6
Thanked 23 Times in 18 Posts
Rep Power: 1
AOG123 is on a distinguished road

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

this should "hopefully" be cleared up in my sample on

http://www.developerbarn.com/microso...x-another.html

thanks AOG

let me know if you have any problems
__________________
If i helped you, make me famous by clicking the
  #4  
Old May 7th, 2008, 02:42 PM
sbenj69's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 84
Thanks: 20
Thanked 24 Times in 19 Posts
Rep Power: 1
sbenj69 is on a distinguished road

Awards Showcase
Microsoft Windows Microsoft Access 
Total Awards: 2

Default

Check out this sample.

I live in Illinois, so, naturually, it has more records.

Comments on this post
Jaykappy agrees: Great help
Attached Files
File Type: zip sample.zip (13.5 KB, 6 views)
  #5  
Old May 7th, 2008, 02:52 PM
Barn Newbie
 
Join Date: Apr 2008
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 1
Jaykappy is an unknown quantity at this point
Default

Thats Exactly what I have been looking for...

I was close on my query but was missing the WHERE clause...

I made a query in the query builder to grab jsut the unique values from that field and was going from that....
Either way I was all mixed up....

What you have is exaclty what I was looking for...

THank you very much...your help is very appreciated...

Have a great day....

Comments on this post
sbenj69 agrees: Glad I could help
  #6  
Old May 7th, 2008, 02:57 PM
sbenj69's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 84
Thanks: 20
Thanked 24 Times in 19 Posts
Rep Power: 1
sbenj69 is on a distinguished road

Awards Showcase
Microsoft Windows Microsoft Access 
Total Awards: 2

Default

well, it's kind of a tricky process when you do it that way..... heh you have to have the form control name to put in the criteria of the query, but you can't build the form control until you have the query in place. I usually build the query, then the form, then go back and edit the query to add the form controls. Very little code is needed by the way.
  #7  
Old May 7th, 2008, 03:02 PM
Barn Newbie
 
Join Date: Apr 2008
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 1
Jaykappy is an unknown quantity at this point
Default

WAIT A SECOND....that was not it...

Sorry about that...

Field 1, Field2, Field3
x c b
x c g
e g l

What I have is a drop down that shows the field names
When I choose Field 3 I want to populate the other drop down box with (b, g, l)
THen if I change the to field1 I want the other dropdown (the same as above) to update to (x, x, e)

That make sense?

THanks for your patience

and help

I can then take these dropdowns and write them to variables to base queries off of...

Field1 X, or Field2c etc

THanks again
  #8  
Old May 7th, 2008, 03:13 PM
sbenj69's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 84
Thanks: 20
Thanked 24 Times in 19 Posts
Rep Power: 1
sbenj69 is on a distinguished road

Awards Showcase
Microsoft Windows Microsoft Access 
Total Awards: 2

Default

Ok, say we have 3 field names....... State, Region, City

You're wanting a combo box to choose the field to populate the other combo box with?

For instance in combo box 1, if I choose city, it will list all cities?
if I choose state, it will list only the states?

If so, that shouldn't be too hard..... I have to do some real work for a bit, then I'll see if I can come up with what you want
  #9  
Old May 7th, 2008, 03:16 PM
Barn Newbie
 
Join Date: Apr 2008
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 1
Jaykappy is an unknown quantity at this point
Default

Yes as in your example...

The 1st drop down will show the field names (I can hard code them if needed)
After Update
The 2nd Drop down needs to have ONLY the UNIQUE values from that field.

So if you choose State the 2nd dropdown will have California, Illinois, Indiana, Ohio

THANK YOU VERY MUCH....
  #10  
Old May 7th, 2008, 04:27 PM
sbenj69's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 84
Thanks: 20
Thanked 24 Times in 19 Posts
Rep Power: 1
sbenj69 is on a distinguished road

Awards Showcase
Microsoft Windows Microsoft Access 
Total Awards: 2

Default

You're right, it's easier to hard code the first combo box. I made mine 2 columns, the first column holding the number, the second the field name. I made the first column width 0 inches so it wouldn't display the number. It stores the number, not the field name.

Then on afterupdate of the first combo box, I did a case statement...

case 1 - make states visible
case 2 - make region visible
case 3 - make cities visible

Here is the sample..... it's really not very difficult after you see what I've done here.
Attached Files
File Type: zip sample.zip (14.6 KB, 4 views)
Closed Thread

  DeveloperBarn Forums > Databases > Microsoft Access

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[ASP/VBScript] Using Dropdown List Value in Database SQL Query richyrich Code Samples 0 April 2nd, 2008 10:05 AM

LinkBacks (?)
LinkBack to this Thread: http://www.developerbarn.com/microsoft-access/174-sql-vba-query.html
Posted By For Type Date
Using 2 combo boxes in conjunction with each other - ASP Free This thread Refback May 21st, 2008 11:20 AM


All times are GMT -4. The time now is 06:47 PM.



Content Relevant URLs by vBSEO 3.2.0