Ouvrir un form a partir d'un autre en affichant les bonnes données

nb01 Messages postés 61 Date d'inscription samedi 7 avril 2007 Statut Membre Dernière intervention 27 novembre 2013 - 28 oct. 2008 à 19:41
zonedhea Messages postés 2 Date d'inscription mardi 23 décembre 2008 Statut Membre Dernière intervention 23 décembre 2008 - 23 déc. 2008 à 15:10
Bonjour,

Mon problème doit être simple mais ne l'est pas pour une débutant en VB comme moi.

J'ai 2 forms
Le form1 contient un Datagrid
Le form2 contient un Detail
Ces 2 forms font appel au même Dataset.

Comme vous l'aurez compris le premier présente une liste et le second et censé être la visualisation détaillée de l'élément que l'utilisateur aura sélectionné dans le Datagrid.

Ma question est simple : comment faire pour que l'utilisateur voir effectivement le detail qui correspond à la ligne sélectionnée dans le Datagrid.

Merci d'avance

Nico

4 réponses

cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
28 oct. 2008 à 20:50
Il te faudrait, je pense, un BindingNavigator branché sur le dataset et auquel tu lui indiquerais l'élément sélectionné pour qu'il te renvoie les données correspondantes.

---- Sevyc64  (alias Casy) ----<hr size="2" width="100%" /># LE PARTAGE EST NOTRE FORCE #    http://aide-office-vba.monforum.com/index.php
0
nb01 Messages postés 61 Date d'inscription samedi 7 avril 2007 Statut Membre Dernière intervention 27 novembre 2013
29 oct. 2008 à 10:00
euh... je suis désolé mais comme je ne connais pas très bien ce truc là je vois pas bien comment je mets ca en place.
sur un des 2 forms sur les 2 ?
0
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
29 oct. 2008 à 21:31
J'ai essayer plusieurs méthodes, mais je n'arrive pas à résoudre ton problème, je ne sais pas comment il faut faire.

---- Sevyc64  (alias Casy) ----<hr size="2" width="100%" /># LE PARTAGE EST NOTRE FORCE #    http://aide-office-vba.monforum.com/index.php
0
zonedhea Messages postés 2 Date d'inscription mardi 23 décembre 2008 Statut Membre Dernière intervention 23 décembre 2008
23 déc. 2008 à 15:10
Voici ce qie j'ais réalisé pour réaliser des recherche dans une MDB, puis d'afficher le détaille de la sélection avant de l'importer dans un chariot, qui écrira son contenu sur ma feuille
Valider en référence Microsoft ADO v6 et DATAgrid V6

A mettre dans un Module


 Global cnx As ADODB.Connection
 Global rst As ADODB.Recordset
 Global rsTitles As ADODB.Recordset
 Global recordsetEC As Recordset
 Global base
 Global ll

Sub coldime1()
  UserForm1.DataGrid1.Columns("Fournisseur").Width = 60
  UserForm1.DataGrid1.Columns("Réf Art").Width = 60
  UserForm1.DataGrid1.Columns("Code Pro").Width = 50
  UserForm1.DataGrid1.Columns("Libellé").Width = 160
  UserForm1.DataGrid1.Columns("C, Opérationnel").Width = 50
  UserForm1.DataGrid1.Columns("MO1").Width = 20
  UserForm1.DataGrid1.Columns("MO2").Width = 20
  UserForm1.DataGrid1.Columns("MO3").Width = 20
UserForm1.DataGrid1.HoldFields
End Sub

Sub coldime2()
  UserForm1.DataGrid1.Columns("Nom_Fournisseur").Width = 70
  UserForm1.DataGrid1.Columns("Reference").Width = 70
  'UserForm1.DataGrid1.Columns("Code Pro").Width = 50
  UserForm1.DataGrid1.Columns("designation").Width = 190
  UserForm1.DataGrid1.Columns("PNI").Width = 50
  'UserForm1.DataGrid1.Columns("MO1").Width = 20
  'UserForm1.DataGrid1.Columns("MO2").Width = 20
  'UserForm1.DataGrid1.Columns("MO3").Width = 20
UserForm1.DataGrid1.HoldFields
End Sub

Code de ma Forme (a adpter en fonction de la MDB


Private Sub ComboBox1_Change()
base = ComboBox1.ListIndex
End Sub


Private Sub CommandButton1_Click()
If TextBox1.Text <> "" Then
  tts = TextBox1.Text
Else
  tts = "%"
End If
If TextBox2.Text <> "" Then
  tts2 = TextBox2.Text
Else
 tts2 = "%"
End If
If TextBox3.Text <> "" Then
  tts3 = TextBox3.Text
Else
 tts3 = "%"
End If




rst.Close
'rst.Open "SELECT Fournisseur ,[Réf Art] ,[Code Pro] ,Libellé ,[C, Opérationnel] ,MO1 ,MO2 ,MO3 FROM Gen_cdp WHERE Libellé LIKE '" & tts & "'", cnx
 
 Select Case (base)
 Case 1
 rst.Open "SELECT Nom_Fournisseur ,Reference ,designation ,PNI  FROM Octave WHERE designation LIKE '" & tts & "' AND Nom_Fournisseur LIKE '" & tts2 & "' AND Reference LIKE '" & tts3 & "'", cnx
 Case 0
 rst.Open "SELECT Fournisseur ,[Réf Art] ,[Code Pro] ,Libellé ,[C, Opérationnel] ,MO1 ,MO2 ,MO3 FROM Gen_cdp WHERE Libellé LIKE '" & tts & "' AND Fournisseur LIKE '" & tts2 & "' AND [Réf Art] LIKE '" & tts3 & "'", cnx
 End Select


Set DataGrid1.DataSource = rst


End Sub


Private Sub CommandButton2_Click()
Select Case (base)
Case 1
ListB.AddItem rst("Reference")
n = ListB.ListCount - 1
ListB.Column(1, n) = rst("designation")
ListB.Column(2, n) = "0" 'rst("MO1")
ListB.Column(3, n) = "0" 'rst("MO2")
ListB.Column(4, n) = "0" 'rst("MO3")
ListB.Column(5, n) = rst("PNI")
Case 0
ListB.AddItem rst("Code Pro")
n = ListB.ListCount - 1
ListB.Column(1, n) = rst("Libellé")
ListB.Column(2, n) = rst("MO1")
ListB.Column(3, n) = rst("MO2")
ListB.Column(4, n) = rst("MO3")
ListB.Column(5, n) = rst("C, Opérationnel")
End Select


ListB.ColumnWidths = "50" & ";" & "180" & ";" & "20" & ";" & "20" & ";" & "20" & ";" & "50"
End Sub


Private Sub CommandButton3_Click()
Dim pri As Double
If ListB.ListCount > 0 Then
 For i = 0 To ListB.ListCount - 1
 Cells(i + ll, 1) = ListB.List(i)
 Cells(i + ll, 2) = ListB.List(i, 1)
 Cells(i + ll, 3) = ListB.List(i, 2)
 Cells(i + ll, 4) = ListB.List(i, 3)
 Cells(i + ll, 5) = ListB.List(i, 4)
 pri = ListB.List(i, 5)
 Cells(i + ll, 6) = pri
 Cells(i + ll, 7) = "1"
 Cells(i + ll, 8).FormulaR1C1 = "=RC[-2]*RC[-1]"
 Next i
End If
End Sub


Private Sub CommandButton4_Click()
txt = ComboBox1.Text
 Set cnx = New ADODB.Connection
 Set rst = New ADODB.Recordset
 Set rsTitles = New ADODB.Recordset


  cnx.Provider = "MSDataShape"
  cnx.Open "Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & txt
 
  tts = "%"
 Select Case (base)
 Case 1
   Label7.Caption = "Nom_Fournisseur"
   Label8.Caption = "designation "
   Label10.Caption = "Reference"
   DataGrid1.ClearFields
   rst.Open "SELECT Nom_Fournisseur ,Reference ,designation ,PNI  FROM Octave WHERE Nom_Fournisseur LIKE '" & tts & "'", cnx
   Set DataGrid1.DataSource = rst
   coldime2
 Case 0
   Label7.Caption = "Fournisseur"
   Label8.Caption = "Libellé"
   Label10.Caption = "Réf Art"
   DataGrid1.ClearFields
   rst.Open "SELECT Fournisseur ,[Réf Art] ,[Code Pro] ,Libellé ,[C, Opérationnel] ,MO1 ,MO2 ,MO3 FROM Gen_cdp WHERE Libellé LIKE '" & tts & "'", cnx
   Set DataGrid1.DataSource = rst
   coldime1
 End Select
  
 
'coldime


' Set DataGrid1.DataSource = rst!nom


'rst.Close
'cnx.Close


End Sub


Private Sub CommandButton5_Click()
On Error GoTo listfin
ListB.RemoveItem (ListB.ListIndex)
listfin:
Exit Sub
End Sub


Private Sub CommandButton6_Click()
ListB.Clear
End Sub


Private Sub CommandButton8_Click()
 UserForm1.Height = 384
 UserForm1.Width = 486.75
 CommandButton8.Visible = False
End Sub


Private Sub CommandButton9_Click()
 UserForm1.Height = 31
 UserForm1.Width = 85
 UserForm1.Top = 0
 CommandButton8.Visible = True
End Sub


Private Sub DataGrid1_DblClick()
CommandButton2_Click
End Sub


Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Select Case (base)
Case 1
Label1.Caption = rst("Nom_Fournisseur")
Label2.Caption = rst("Reference")
Label3.Caption = "" 'rst("Code Pro")
Label4.Caption = rst("designation")
Label9.Caption = rst("PNI") & " €"
Case 0
Label1.Caption = rst("Fournisseur")
Label2.Caption = rst("Réf Art")
Label3.Caption = rst("Code Pro")
Label4.Caption = rst("Libellé")
Label9.Caption = rst("C, Opérationnel") & " €"
End Select
'tests
'Cells(1, 1) = rst("Code Pro")
'Cells(1, 2) = rst("Libellé")
'Cells(1, 3) = rst("MO1")
'Cells(1, 4) = rst("MO2")
'Cells(1, 5) = rst("MO3")
'Cells(1, 6) = rst("C, Opérationnel")


End Sub


Private Sub UserForm_Activate()
ComboBox1.Clear
pt = 3
Do While Worksheets("Sources").Cells(pt, 1) <> ""
 ComboBox1.AddItem Worksheets("Sources").Cells(pt, 1)
 pt = pt + 1
Loop
ComboBox1.Text = ComboBox1.List(0)
Exit Sub


 Set cnx = New ADODB.Connection
 Set rst = New ADODB.Recordset
 Set rsTitles = New ADODB.Recordset


  cnx.Provider = "MSDataShape"
  'cnx.Open "Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\devt\outil\test1\bd2.mdb"
  cnx.Open "Data Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\bdd\Fournisseurs.mdb"
 
 
' cnx.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};dbq=" & "e:\devt\outil\test1\bd1.mdb" & ";"
 'cnx.Open
 tts = "##"
 rst.Open "SELECT Nom_Fournisseur ,Reference ,designation ,PNI  FROM Octave WHERE Nom_Fournisseur LIKE '" & tts & "'", cnx
' rst.Open "SELECT Fournisseur ,[Réf Art] ,[Code Pro] ,Libellé ,[C, Opérationnel] ,MO1 ,MO2 ,MO3 FROM Gen_cdp WHERE Libellé LIKE '" & tts & "'", cnx


 'rst.Open "SELECT Nom, Prénom, Date FROM client WHERE Nom LIKE '" & tts & "'", cnx
 'rst.Open "SELECT Nom, Prénom, Date FROM client WHERE Date > #15/12/2005# ", cnx, adOpenDynamic, adLockOptimistic, adCmdText


  
  Set DataGrid1.DataSource = rst
'coldime


' Set DataGrid1.DataSource = rst!nom


'rst.Close
'cnx.Close
End Sub

ZoneDHEA
0
Rejoignez-nous