View Single Post
Old July 21st, 2006, 08:08 AM
sparsh2010 sparsh2010 is offline
Registered User
Join Date: Jul 2006
Location: hyderabad, andhra pradesh, India.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sparsh2010
Default Not able to pass the combo box value to SQL query

hi Friends i am new bie in VBA ( MS access )

I have created a program which reads the text file then creates the csv file and creates a access databse file and then do some query

There are two forms and one module used in project - the form 1 executes the call for a module ( which reads the text file and creates a csv file ) then back to form 1 then form 1 imports the data from csv file to access databse file then invokes the VBquestion asking user that if he wants to do query if selected " yes " then it invokes another form in which user has to select the value from combo box and then the project should fetch the record

Problem - when starting from form1 and then invoking form2 then running the query " it asks me for the value " so i need to input the value even after i have selected from combo box
but when starting from form2 if i select the value in combox box , it runs the query

below is given code

Form 1
( this part reads the text file and creates a csv file )

Private Sub Read_Next_Click()

    Call Parse_Employee_File(strdir)

End Sub

Form 1

( This part imports the data from csv to access database file and invokes the form 2 )

Private Sub Command19_Click()
    Dim strSpec, strTable, strFile As String
    Dim intLawver As Long

    strSpec = "Employee Link Specification"
    strTable = "Employeedb"
    strFile = strdir & "\Employee" & ".csv"
    Debug.Print "Importing " & strFile

    DoCmd.TransferText acImportDelim, strSpec, strTable, strFile
    Debug.Print strFile & " has been imported"

    MsgBox "File import completed"

    iReply = MsgBox("Do you want to execute the query", vbQuestion + vbYesNo)

    If (iReply = vbYes) Then
       Form_Form2.Visible = True
    End If

End Sub

Form 2

Private Sub Combo0_Change()

      Dim InputID As String
      InputID = Form_Form2.Combo0.SelText

      If InputID <> "" Then
        MsgBox ("you have selected -" & InputID)
      End If

       strsql = "query1"
       DoCmd.SetWarnings False
       DoCmd.OpenQuery strsql
       Debug.Print "Check"

End Sub

The SQL query wrritten is

SELECT employeedb.ID, employeedb.Fstname, employeedb.LStname, employeedb.Number, employeedb.Address
FROM employeedb
WHERE (employeedb.ID=forms!form_form2!combo0);

Can anybody please tell me why i am not able to pass the value from form 2 to SQL query please suggest whereever i have to make change