I've been looking for some answers on stackoverflow, but I havent found any. So I decided to ask my own question.
I'm coding a search engine in VBA in order to find contracts in my DB.
This is what I've done so far
Private Sub cmd_recherche_Click()
Dim strTable As String, strField As String, strCriteria As String, strSql As String
Dim Criter As Variant
If Me.listbox_search = "Num_contract" Then
Debug.Print Me.listbox_search
strTable = "AFN_LOT0"
strField = "NUMERO"
strCriteria = strTable & "." & strField & " Like """ & Me.txt_critere & """"
strSql = "SELECT DISTINCTROW " & strTable & "." & strField & "," & strTable & ".FORMULE," & strTable & ".DATE_EFFET," & strTable & ".DATE_ECHEANCE," & strTable & ".ETAT," & strTable & ".CODE_RESILIATION," & strTable & ".DATE_RESIL," & strTable & ".DATE_OPERATION"
strSql = strSql & " FROM " & strTable
strSql = strSql & " WHERE " & strCriteria & ";"
Me.lst_resultat.RowSource = strSql
Me.lst_resultat.Requery
End if
End sub
Now I'd like to be able to double click on a result in the listbox (lst_resultat) and open another form (F_InfosContract) which would contain all the information of the contract(dispatched in separate tables all linked together by the field ID_SOR) selected in the listbox.
I've tried this but it only opens the form with nothing in the listbox..
Private Sub lst_resultat_DblClick(Cancel As Integer)
Dim stLinkCriteria As String
Dim Selection As String
Selection = lst_resultat.Value
stLinkCriteria = Selection
DoCmd.OpenForm "F_InfosContract", , , stLinkCriteria
End Sub
If someone could help me out, that would be nice
Sorry for my english
Mdgy