Solved Copy data from listbox to subform (1 Viewer)

Noel96334

New member
Local time
Today, 08:10
Joined
Jun 12, 2011
Messages
12
Hi, I'm newbee here and my English is not so good. So I'm going to try to explain my problem.
I have made a order db with main (frmOrderMain) and subform (frmOrderSub1). In the Order main form
I have a listbox with products, populated from the table tblProducts. There is also a combobox to filter the
products in the listbox. So far everything works well.
What I would like to do now, is copy the selected record in the listbox to the subform. I have searched in the
forums and found a solution with a sql-statement. The problem is that I can not modify this for my issue.

Is there anyone who can help me with this please ?

Thanks in advance.
 

Attachments

  • Test1.accdb
    588 KB · Views: 97

Ranman256

Well-known member
Local time
Today, 02:10
Joined
Apr 9, 2015
Messages
4,337
copy can use either:
sql method:
update t.subtable set [field]= forms!fMasterform!listbox where [id]=forms!fMasterform!txtID

or
just copy value:
me.subform.form.txtBox = forms!fMasterform!listbox
 

Eugene-LS

Registered User.
Local time
Today, 09:10
Joined
Dec 7, 2018
Messages
481
What I would like to do now, is copy the selected record in the listbox to the subform.
Here you are! :giggle:
 

Attachments

  • Test1_v02.zip
    43.3 KB · Views: 96

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:10
Joined
Feb 19, 2002
Messages
43,293
Instead of using an unbound listbox in the main form, use a bound combo in the subform. This method requires no coding.
 

Noel96334

New member
Local time
Today, 08:10
Joined
Jun 12, 2011
Messages
12
Here you are! :giggle:
Thanks Eugene for the reply ! But, I get an error when I make an new order.
Error 3201 You can't add or change a record because there is missing
a related record in tblOrders.
 

Noel96334

New member
Local time
Today, 08:10
Joined
Jun 12, 2011
Messages
12

Attachments

  • Problem.jpg
    Problem.jpg
    133.7 KB · Views: 71

Eugene-LS

Registered User.
Local time
Today, 09:10
Joined
Dec 7, 2018
Messages
481
but the problem still the same.
It seems I found what's wrong.
This is my mistake - as it turned out, you can not add records to the child table until the record is saved in the main one.
 

Attachments

  • Test1_v04.zip
    47.2 KB · Views: 92

moke123

AWF VIP
Local time
Today, 02:10
Joined
Jan 11, 2013
Messages
3,920
Note that if you input a large quantity you get the wrong result. Probably because you have the quantity field as byte datatype.
 

June7

AWF VIP
Local time
Yesterday, 22:10
Joined
Mar 9, 2014
Messages
5,474
It seems I found what's wrong.
This is my mistake - as it turned out, you can not add records to the child table until the record is saved in the main one.
Yes, if you enforce referential integrity.

Usually, I would agree with earlier advice to have instead of unbound listbox and quantity textbox on main form, have bound combobox and textbox on subform; and remove tblProducts from subform RecordSource. Could still have conditional combobox on subform, although that gets a bit tricky with continuous/datasheet form.

Is your issue now solved?
 

Eugene-LS

Registered User.
Local time
Today, 09:10
Joined
Dec 7, 2018
Messages
481
Is your issue now solved?
No, unfortunately.
Today I urgently need to fix reporting to the compulsory health insurance fund, not a lot of work, but it needs to be done.
 

Noel96334

New member
Local time
Today, 08:10
Joined
Jun 12, 2011
Messages
12
Yes, if you enforce referential integrity.

Usually, I would agree with earlier advice to have instead of unbound listbox and quantity textbox on main form, have bound combobox and textbox on subform; and remove tblProducts from subform RecordSource. Could still have conditional combobox on subform, although that gets a bit tricky with continuous/datasheet form.

Is your issue now solved?
YES ! It works well ! Great job ! Thank you so match too all of you !
 

moke123

AWF VIP
Local time
Today, 02:10
Joined
Jan 11, 2013
Messages
3,920
Does the Quantity ever exceed 255? With byte datatype, I think the largest number is 255.
 

Noel96334

New member
Local time
Today, 08:10
Joined
Jun 12, 2011
Messages
12
Does the Quantity ever exceed 255? With byte datatype, I think the largest number is 255.
Thanks for the reply. Yes I know, the current datatype is "Byte". But we're working with small
volumes, this is sufficient. I appreciate your help ! Thanks so match !
 

Users who are viewing this thread

Top Bottom