Forms Running Queries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • allenpramod
    New Member
    • Nov 2006
    • 7

    #1

    Forms Running Queries

    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_teache r,division from " & me.cmbdist.text & " where name_school = "[forms]![Form6]![cmbschool].column(0)"; in Query3

    and i tried this one also

    select sno,name_teache r,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_Chang e()
    Dim stDocName As String
    stDocName = "Query3"
    DoCmd.OpenQuery stDocName, acViewPreview, acEdit
    End Sub

    actually in district table district_names field have(bokaro,dum ka,chaibasa) data
    these are again tables-for bokaro,dumka,ch aibasa data is same as (sno,name_teach er,division). tell me urgent
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    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.

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      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

      Code:
      SELECT sno,name_teacher,division 
      FROM district  
      WHERE name_school = "[forms]![Form6]![cmbschool].column(0)
      AND district_name='" & me.cmbdist.text & "'";
      Mary

      Comment

      • allenpramod
        New Member
        • Nov 2006
        • 7

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


        dim strsql as string
        strsql="Query3"
        docmd.OpenQuery "Query3",acView Normal,, 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.SetF ocus
        STR = cmbdist.Text
        Me.cmbschool.Se tFocus
        STR1 = cmbschool.Text
        STRSQL = "SELECT SNO,NAME_OF_TEA CHER,DIVISION,H OME_BLOCK FROM " & STR & " WHERE NAME_OF_SCHOOL= '" & STR1 & "' ;"
        Debug.Print "SQL Statement: " & STRSQL
        Set DBS = CurrentDb
        Set GDF = DBS.CreateQuery Def(QUERY3, STRSQL)

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          You haven't answered the question about what is your table name?

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

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

            Comment

            Working...