Connecting Tech Pros Worldwide Forums | Help | Site Map

Forms Running Queries

Newbie
 
Join Date: Nov 2006
Posts: 7
#1: Dec 12 '06
i have a form which will display district_names in combo box(cmbdist), when i select this it will display name_school in combo box(cmbschool), when i select this it will run a query how? i used to do like this but error occuring syntax error in FROM clause.

select sno,name_teacher,division from " & me.cmbdist.text & " where name_school = "[forms]![Form6]![cmbschool].column(0)"; in Query3

and i tried this one also

select sno,name_teacher,division from "[forms][Form6][cmbdist].text" where name_school = "[forms]![Form6]![cmbschool].column(0)"; in Query3

i didnt get

this is my combo box(cmbschool) vba code

Private Sub CMBSCHOOL_Change()
Dim stDocName As String
stDocName = "Query3"
DoCmd.OpenQuery stDocName, acViewPreview, acEdit
End Sub

actually in district table district_names field have(bokaro,dumka,chaibasa) data
these are again tables-for bokaro,dumka,chaibasa data is same as (sno,name_teacher,division). tell me urgent

NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#2: Dec 12 '06

re: Forms Running Queries


What you've posted for the queries seems to start in the middle of a line. The first quotes are missing and it doesn't show what you do with the resultant string.
Can you repost with code tags and the whole lines please.
Without that this just doesn't make sense.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,885
#3: Dec 13 '06

re: Forms Running Queries


It's not clear if cmbdist hold the names of your tables or if you have one table called district. If it's the latter then you will need to do the following

Expand|Select|Wrap|Line Numbers
  1. SELECT sno,name_teacher,division 
  2. FROM district  
  3. WHERE name_school = "[forms]![Form6]![cmbschool].column(0)
  4. AND district_name='" & me.cmbdist.text & "'";
  5.  
Mary
Newbie
 
Join Date: Nov 2006
Posts: 7
#4: Dec 13 '06

re: Forms Running Queries


In queries(Query3)
--------------
select sno,name_teacher,division from " & me.cmbdist.text & " where name_school = "[forms]![Form6]![cmbschool].column(0)";


dim strsql as string
strsql="Query3"
docmd.OpenQuery "Query3",acViewNormal,, acEdit

it didnt open query. i tried another one like this but wont create a query.how


Dim STRSQL, STR As String
Dim STR1 As String
Set DBS = CurrentDb
Me.cmbdist.SetFocus
STR = cmbdist.Text
Me.cmbschool.SetFocus
STR1 = cmbschool.Text
STRSQL = "SELECT SNO,NAME_OF_TEACHER,DIVISION,HOME_BLOCK FROM " & STR & " WHERE NAME_OF_SCHOOL= '" & STR1 & "' ;"
Debug.Print "SQL Statement: " & STRSQL
Set DBS = CurrentDb
Set GDF = DBS.CreateQueryDef(QUERY3, STRSQL)
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,885
#5: Dec 13 '06

re: Forms Running Queries


You haven't answered the question about what is your table name?
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#6: Dec 14 '06

re: Forms Running Queries


And I can't help either as you've ignored my post completely (Post #2).
Reply


Similar Microsoft Access / VBA bytes