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.Connection
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, adLockOptimistic
If rs.RecordCount > 0 Then
Company = rs!Company
Address = rs!Address
Contactperson = rs!Contactperson
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, adLockOptimistic
If rs.RecordCount > 0 Then
Me.[JMTPORDETAILSUBFORM].SetFocus
Do Until rs.EOF
Me.[JMTPORDETAILSUBFORM]![Particular] = rs!Particular
Me.[JMTPORDETAILSUBFORM]![Qty] = rs!Qty
Me.[JMTPORDETAILSUBFORM]![PartNumber] = rs!PartNumber
Me.[JMTPORDETAILSUBFORM]![id] = rs!id
Me.[JMTPORDETAILSUBFORM]![flag] = rs!flag
Me.Refresh
'DoCmd.GoToRecord , , 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.Connection
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, adLockOptimistic
If rs.RecordCount > 0 Then
rs!Company = Company
rs!Address = Address
rs!Contactperson = 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, adLockOptimistic
'If rs.RecordCount > 0 Then
Me.[JMTPORDETAILSUBFORM].SetFocus
Do Until rs.EOF
rs!Particular = Me.[JMTPORDETAILSUBFORM]![Particular]
rs!Qty = Me.[JMTPORDETAILSUBFORM]![Qty]
rs!PartNumber = Me.[JMTPORDETAILSUBFORM]![PartNumber]
'DoCmd.GoToRecord , , 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
19 2965
It seems that my post is not much clear because i dont get any reply from you guys i reconstruct my wording
In my Form
I have a listbox and the Value of this "column" (Listbox) is ID, the user can select a multiple id
then a subform that must display a "record" in a table then a textbox (unbound) and a commandbutton to execute
the scenario is like this, The user will select a ID in column then click the commandbutton
the textbox will get the value from a table then in subform it also get the record in another table
The value for Textbox is working properly my problem is in the subform i noticed that everytime i choose
an id and click the commandbutton the record that display in my subform is duplicating, and if i change the
listbox property into multiselect (simple) i got an error
this is the error " Run-time error -2147217900(80040e14) Syntax error (missing operator)in query expression
'ID =',
This is my code in Retriving Value into the form -
-
Private Sub cmdtest_Click()
-
Dim rs As New ADODB.Recordset
-
Dim cnn As New ADODB.Connection
-
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, adLockOptimistic
-
If rs.RecordCount > 0 Then
-
Company = rs!Company
-
Address = rs!Address
-
Contactperson = rs!Contactperson
-
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, adLockOptimistic
-
'If rs.RecordCount > 0 Then
-
Me.[JMTPORDETAILSUBFORM].SetFocus
-
Do Until rs.EOF
-
Me.[JMTPORDETAILSUBFORM]![Particular] = rs!Particular
-
Me.[JMTPORDETAILSUBFORM]![Qty] = rs!Qty
-
Me.[JMTPORDETAILSUBFORM]![PartNumber] = rs!PartNumber
-
Me.[JMTPORDETAILSUBFORM]![id] = rs!id
-
Me.[JMTPORDETAILSUBFORM]![flag] = rs!flag
-
Me.Refresh
-
'DoCmd.GoToRecord , , 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
-
And this is the Code for Saving Value to Table -
Private Sub Command23_Click()
-
Dim rs As New ADODB.Recordset
-
Dim cnn As New ADODB.Connection
-
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, adLockOptimistic
-
If rs.RecordCount > 0 Then
-
rs!Company = Company
-
rs!Address = Address
-
rs!Contactperson = 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, adLockOptimistic
-
'If rs.RecordCount > 0 Then
-
Me.[JMTPORDETAILSUBFORM].SetFocus
-
Do Until rs.EOF
-
rs!Particular = Me.[JMTPORDETAILSUBFORM]![Particular]
-
rs!Qty = Me.[JMTPORDETAILSUBFORM]![Qty]
-
rs!PartNumber = Me.[JMTPORDETAILSUBFORM]![PartNumber]
-
'DoCmd.GoToRecord , , acNewRec
-
-
rs.Update
-
rs.MoveNext
-
Loop
-
-
Else
-
Company = vbNullString
-
Address = vbNullString
-
Contactperson = vbNullString
-
Designation = vbNullString
-
Telno = vbNullString
-
Faxno = vbNullString
-
End If
-
End Sub
-
Thanks for advance hope its kinda clear
Try this ... -
-
Private Sub cmdtest_Click()
-
Dim rs As New ADODB.Recordset
-
Dim cnn As New ADODB.Connection
-
Dim valSelect As Variant
-
Dim i As Integer
-
Dim sSql As String
-
-
Set cnn = CurrentProject.Connection
-
For Each valSelect In Me!List20.ItemsSelected
-
sSql = "select * from [DR_Table] where id =" & Me!List20.ItemData(valSelect)
-
rs.Open sSql, cnn, adOpenKeyset, adLockOptimistic
-
If rs.RecordCount > 0 Then
-
Me!Company = rs!Company
-
Me!Address = rs!Address
-
Me!Contactperson = rs!Contactperson
-
Me!Designation = rs!Designation
-
Me!Telno = rs!Telno
-
Me!Faxno = rs!Faxno
-
End If
-
rs.Close
-
Set rs = Nothing
-
-
ssql = "SELECT * FROM [Dr_Detail_Table] WHERE ID=" & Me!List20.ItemData(valSelect)
-
rs.Open ssql, cnn, adOpenKeyset, adLockOptimistic
-
rs.MoveLast
-
rs.MoveFirst
-
If rs.RecordCount > 0 Then
-
Me![JMTPORDETAILSUBFORM].SetFocus
-
Do Until rs.EOF
-
Me![JMTPORDETAILSUBFORM]![Particular] = rs!Particular
-
Me![JMTPORDETAILSUBFORM]![Qty] = rs!Qty
-
Me![JMTPORDETAILSUBFORM]![PartNumber] = rs!PartNumber
-
Me![JMTPORDETAILSUBFORM]![id] = rs!id
-
Me![JMTPORDETAILSUBFORM]![flag] = rs!flag
-
Me.Refresh
-
DoCmd.GoToRecord , , acNewRec
-
rs.MoveNext
-
Loop
-
rs.Close
-
Set rs = Nothing
-
Else
-
Me! Company = vbNullString
-
Me! Address = vbNullString
-
Me! Contactperson = vbNullString
-
Me! Designation = vbNullString
-
Me! Telno = vbNullString
-
Me! Faxno = vbNullString
-
End If
-
Next valSelect
-
-
End Sub
-
If you bind the form to the table where you want the records saved then you won't need the second piece of code.
Mary
hi mary i tried the code i have errors
Run-Time errors '2499'
You cant use the GoToRecord action or method on an object in Design view
Then if i click Debug
It point to this code
DoCmd.GoToRecord , , acNewRec
Hi no errors now i forgot to change the properties of my list box into a multiselect but i have still some issues the record in subforms are duplicating
Try substituting this code ... -
If rs.RecordCount > 0 Then
-
Me![JMTPORDETAILSUBFORM].SetFocus
-
Do Until rs.EOF
-
Me![JMTPORDETAILSUBFORM].Form![Particular] = rs!Particular
-
Me![JMTPORDETAILSUBFORM].Form![Qty] = rs!Qty
-
Me![JMTPORDETAILSUBFORM].Form![PartNumber] = rs!PartNumber
-
Me![JMTPORDETAILSUBFORM].Form![id] = rs!id
-
Me![JMTPORDETAILSUBFORM].Form![flag] = rs!flag
-
DoCmd.GoToRecord , , acNext
-
rs.MoveNext
-
Loop
-
rs.Close
-
Set rs = Nothing
-
Else
-
It has an error saying 'Run -Time Error '2105';
You cant go to the specified record
I try to comment the
DoCmd.GoToRecord , , acNewRec and it has no errors but it still duplicating the records in subform
It has an error saying 'Run -Time Error '2105';
You cant go to the specified record
I try to comment the
DoCmd.GoToRecord , , acNewRec and it has no errors but it still duplicating the records in subform
The new code I gave you had - DoCmd.GoToRecord , , acNext
This is the structure of my table
from table DR_Detail_Table: I have 3 records
ID Particular QTY PARTNUMBER Flag
DRF-00001 CPU 1 Desc No
DRF-00001 MOnitor 1 Desc No
DRF-00001 PowerCord 1 Desc No
In Subform View - This is the one i view everytime i run the commandbutton
and i observe it always the last record only
ID Particular QTY PARTNUMBER Flag
DRF-00001 PowerCord 1 Desc No
DRF-00001 PowerCord 1 Desc No
DRF-00001 PowerCord 1 Desc No
Yes mary this is the code that you gave no errors but still duplicates the record on the subform
sSql = "SELECT * FROM [Dr_Detail_Table] WHERE ID=" & Me!List20.ItemData(valSelect)
rs.Open sSql, cnn, adOpenKeyset, adLockOptimistic
rs.MoveLast
rs.MoveFirst
If rs.RecordCount > 0 Then
Me![JMTPORDETAILSUBFORM].SetFocus
Do Until rs.EOF
Me![JMTPORDETAILSUBFORM]![Particular] = rs!Particular
Me![JMTPORDETAILSUBFORM]![Qty] = rs!Qty
Me![JMTPORDETAILSUBFORM]![PartNumber] = rs!PartNumber
Me![JMTPORDETAILSUBFORM]![id] = rs!id
Me![JMTPORDETAILSUBFORM]![flag] = rs!flag
Me.Refresh
DoCmd.GoToRecord , , acNewRec
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Else
Me!Company = vbNullString
Me!Address = vbNullString
Me!Contactperson = vbNullString
Me!Designation = vbNullString
Me!Telno = vbNullString
Me!Faxno = vbNullString
End If
Next valSelect
End Sub
Run this query substituting a valid ID for 1. -
SELECT * FROM [Dr_Detail_Table] WHERE ID=1
What results are you getting?
This what i got if i run the query uve gave
DRF - 00001 Memory 2GB 1 RTS-0909TY-STYA No
DRF - 00001 CPU 1 WR1-0FGQE-0091 No
DRF - 00001 PowerCord 1 QDSG7689 No
This what i got if i run the query uve gave
DRF - 00001 Memory 2GB 1 RTS-0909TY-STYA No
DRF - 00001 CPU 1 WR1-0FGQE-0091 No
DRF - 00001 PowerCord 1 QDSG7689 No
OK now is the subform of the New form by any chance set to the Record Source of the Dr_Detail_Table. If so then we are taking records from that table and readding them. Or is there a new table for these records?
YEs the subform of the new form is set to the record of DR_Detail_Table,
and there no new table for these record, it will appear in a same table (DR_Detail_TAble)
YEs the subform of the new form is set to the record of DR_Detail_Table,
and there no new table for these record, it will appear in a same table (DR_Detail_TAble)
But these records are already in that table so by adding them you are creating duplicates.
i use one table in 2 different subform because my purpose
is in one of the subform is the list of all product with no tags, then i will
past to my new subform and still with a complete list of products with no tags
then i will tag the product manually in the new form then save it
so in my table i captured all the list of my product wig tag or without tag,
is my analysis wont make any sense? would you give me another idea?
i use one table in 2 different subform because my purpose
is in one of the subform is the list of all product with no tags, then i will
past to my new subform and still with a complete list of products with no tags
then i will tag the product manually in the new form then save it
so in my table i captured all the list of my product wig tag or without tag,
is my analysis wont make any sense? would you give me another idea?
I'm not sure why you need the two tables but you don't need to subform records.
Once you add the record to the POR_Table the subform will populate automatically with the existing records.
Just remove the code to add the records to the subform and see what happens.
Mary
Only the Value in the Text Box will appear, but no records appearing in the subform : (
Only the Value in the Text Box will appear, but no records appearing in the subform : (
Try adding this to the end of the code. -
-
Me![JMTPORDETAILSUBFORM].Requery
Private Sub cmdtest_Click()
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection
Dim valSelect As Variant
Dim i As Integer
Dim sSql As String
Set cnn = CurrentProject.Connection
For Each valSelect In Me!List20.ItemsSelected
sSql = "select * from [DR_Table] where id =" & Me!List20.ItemData(valSelect)
rs.Open sSql, cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
Me!Company = rs!Company
Me!Address = rs!Address
Me!Contactperson = rs!Contactperson
Me!Designation = rs!Designation
Me!Telno = rs!Telno
Me!Faxno = rs!Faxno
Me![JMTPORDETAILSUBFORM].Requery
Else
Me!Company = vbNullString
Me!Address = vbNullString
Me!Contactperson = vbNullString
Me!Designation = vbNullString
Me!Telno = vbNullString
Me!Faxno = vbNullString
End If
Next valSelect
End Sub
Mary Do i put the code correctly? still no records appearing only the textbox
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Alienz |
last post by:
I have a subform where I have a subform with 20 options to select
from. When I set the multiselect property to simple and select
multiple options, nothing is stored. I have another table with...
|
by: Simon P |
last post by:
Hello group, I'm in desperate need of help. Here goes :
I have the following tables : CONTACTS (ContactID, FirstName,
LastName, Company, etc.), SHOWS (ShowID, ShowDescription) and
SHOWDETAILS...
|
by: Paul T. Rong |
last post by:
I have a listbox (of product names) control on my form. I want to pass the
selected item (a product name) to a subform, and the product unitprice
should apear automatically next to the product name...
|
by: Chris Leuty |
last post by:
I am populating a multiselect Listbox from a dataset, with the content of
the listbox filled by one table, and the selections determined from another
table. So far, I have been keeping the dataset...
|
by: Ecohouse |
last post by:
I'm using Access 97 (don't ask) for a project. I have a search form
that will then return results to another form. I need to see the
results in this type of format:
Project Date ...
|
by: colleen1980 |
last post by:
Hi: I am trying to pull all the values from the listbox. But the ASP
code shows only the last record. Needs help
HTML
<html>
<head>
|
by: bbcrock |
last post by:
Real quick question, can anyone point me to an article discussing how
to use a listbox where the data comes from a lookup table to store
multiple records in a child table? I created a form based...
|
by: jh |
last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a
textbox but can't figure out how to accomplish this for a listbox. Any
help? Thanks.
|
by: weirdguy |
last post by:
Hello,
Just for anyone information, there is a similar title "Search in Listbox" but it is via Combo Box. In case, anyone need it, I put a link to here.
Please let me know if I break any rules...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |