Hi guys good day, can anybody help for my problem
The Scenario is
A Listbox (ID) - Multiple Select - everytime i choose in the list box
the following outbound textbutton and subform will retrieve in my form-
the folliwng value will get from another form
i have a code but i need to customize it because everytime i choose ID in my list box my value in subform is multiplying by row i mean the value in subform is duplicating
this my code in my command button:
'For Retrival of Values in another form'
Option Compare Database
Option Explicit
Dim cboOriginator As ComboBox
Private Sub cmdtest_Click()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connectio n
Dim i As Integer
Dim sSql As String
Dim ssql1 As String
Dim rs1 As New ADODB.Recordset
Set cnn = CurrentProject. Connection
sSql = "select * from [DR_Table] where id =" & List20.Value
rs.Open sSql, cnn, adOpenKeyset, adLockOptimisti c
If rs.RecordCount > 0 Then
Company = rs!Company
Address = rs!Address
Contactperson = rs!Contactperso n
Designation = rs!Designation
Telno = rs!Telno
Faxno = rs!Faxno
rs.Close
ssql1 = "SELECT * FROM [Dr_Detail_Table] WHERE ID=" & List20.Value
rs.Open ssql1, cnn, adOpenKeyset, adLockOptimisti c
If rs.RecordCount > 0 Then
Me.[JMTPORDETAILSUB FORM].SetFocus
Do Until rs.EOF
Me.[JMTPORDETAILSUB FORM]![Particular] = rs!Particular
Me.[JMTPORDETAILSUB FORM]![Qty] = rs!Qty
Me.[JMTPORDETAILSUB FORM]![PartNumber] = rs!PartNumber
Me.[JMTPORDETAILSUB FORM]![id] = rs!id
Me.[JMTPORDETAILSUB FORM]![flag] = rs!flag
Me.Refresh
'DoCmd.GoToReco rd , , acNewRec
rs.MoveNext
Loop
rs.Close
Else
Company = vbNullString
Address = vbNullString
Contactperson = vbNullString
Designation = vbNullString
Telno = vbNullString
Faxno = vbNullString
End If
End If
End Sub
This is my code for Saving in the value in table
'For Saving
Private Sub Command23_Click ()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connectio n
Dim i As Integer
Dim sSql As String
Dim ssql1 As String
Dim rs1 As New ADODB.Recordset
Set cnn = CurrentProject. Connection
sSql = "select * from [POR_Table] where id =" & List20.Value
rs.Open sSql, cnn, adOpenKeyset, adLockOptimisti c
If rs.RecordCount > 0 Then
rs!Company = Company
rs!Address = Address
rs!Contactperso n = Contactperson
rs!Designation = Designation
rs!Telno = Telno
rs!Faxno = Faxno
rs.Update
rs.Close
ssql1 = "SELECT * FROM [DR_Detail_Table] WHERE ID=" & List20.Value
rs.Open ssql1, cnn, adOpenKeyset, adLockOptimisti c
'If rs.RecordCount > 0 Then
Me.[JMTPORDETAILSUB FORM].SetFocus
Do Until rs.EOF
rs!Particular = Me.[JMTPORDETAILSUB FORM]![Particular]
rs!Qty = Me.[JMTPORDETAILSUB FORM]![Qty]
rs!PartNumber = Me.[JMTPORDETAILSUB FORM]![PartNumber]
'DoCmd.GoToReco rd , , acNewRec
rs.Update
rs.MoveNext
Loop
Else
Company = vbNullString
Address = vbNullString
Contactperson = vbNullString
Designation = vbNullString
Telno = vbNullString
Faxno = vbNullString
End If
End Sub
Thank you so much in advance
The Scenario is
A Listbox (ID) - Multiple Select - everytime i choose in the list box
the following outbound textbutton and subform will retrieve in my form-
the folliwng value will get from another form
i have a code but i need to customize it because everytime i choose ID in my list box my value in subform is multiplying by row i mean the value in subform is duplicating
this my code in my command button:
'For Retrival of Values in another form'
Option Compare Database
Option Explicit
Dim cboOriginator As ComboBox
Private Sub cmdtest_Click()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connectio n
Dim i As Integer
Dim sSql As String
Dim ssql1 As String
Dim rs1 As New ADODB.Recordset
Set cnn = CurrentProject. Connection
sSql = "select * from [DR_Table] where id =" & List20.Value
rs.Open sSql, cnn, adOpenKeyset, adLockOptimisti c
If rs.RecordCount > 0 Then
Company = rs!Company
Address = rs!Address
Contactperson = rs!Contactperso n
Designation = rs!Designation
Telno = rs!Telno
Faxno = rs!Faxno
rs.Close
ssql1 = "SELECT * FROM [Dr_Detail_Table] WHERE ID=" & List20.Value
rs.Open ssql1, cnn, adOpenKeyset, adLockOptimisti c
If rs.RecordCount > 0 Then
Me.[JMTPORDETAILSUB FORM].SetFocus
Do Until rs.EOF
Me.[JMTPORDETAILSUB FORM]![Particular] = rs!Particular
Me.[JMTPORDETAILSUB FORM]![Qty] = rs!Qty
Me.[JMTPORDETAILSUB FORM]![PartNumber] = rs!PartNumber
Me.[JMTPORDETAILSUB FORM]![id] = rs!id
Me.[JMTPORDETAILSUB FORM]![flag] = rs!flag
Me.Refresh
'DoCmd.GoToReco rd , , acNewRec
rs.MoveNext
Loop
rs.Close
Else
Company = vbNullString
Address = vbNullString
Contactperson = vbNullString
Designation = vbNullString
Telno = vbNullString
Faxno = vbNullString
End If
End If
End Sub
This is my code for Saving in the value in table
'For Saving
Private Sub Command23_Click ()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connectio n
Dim i As Integer
Dim sSql As String
Dim ssql1 As String
Dim rs1 As New ADODB.Recordset
Set cnn = CurrentProject. Connection
sSql = "select * from [POR_Table] where id =" & List20.Value
rs.Open sSql, cnn, adOpenKeyset, adLockOptimisti c
If rs.RecordCount > 0 Then
rs!Company = Company
rs!Address = Address
rs!Contactperso n = Contactperson
rs!Designation = Designation
rs!Telno = Telno
rs!Faxno = Faxno
rs.Update
rs.Close
ssql1 = "SELECT * FROM [DR_Detail_Table] WHERE ID=" & List20.Value
rs.Open ssql1, cnn, adOpenKeyset, adLockOptimisti c
'If rs.RecordCount > 0 Then
Me.[JMTPORDETAILSUB FORM].SetFocus
Do Until rs.EOF
rs!Particular = Me.[JMTPORDETAILSUB FORM]![Particular]
rs!Qty = Me.[JMTPORDETAILSUB FORM]![Qty]
rs!PartNumber = Me.[JMTPORDETAILSUB FORM]![PartNumber]
'DoCmd.GoToReco rd , , acNewRec
rs.Update
rs.MoveNext
Loop
Else
Company = vbNullString
Address = vbNullString
Contactperson = vbNullString
Designation = vbNullString
Telno = vbNullString
Faxno = vbNullString
End If
End Sub
Thank you so much in advance
Comment