473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

listbox, subform insert help

Joe
Hi all,

I haven't worked with Access in a LONG time and was hoping someone can
help me with the following issue:

I have 3 tables (STUDENTS, LANGUAGES, and STUDENTS_LANGUAGES).

The schemas are:

STUDENTS
STUDENT_ID - PK
NAME

LANGUAGES
LANG_ID - PK
LANGUAGE

STUDENTS_LANGUAGES
STU_LANG_ID PK
STUDENT_ID - FK
LANG_ID - FK

I have a form to insert data for students. This form contains a list
box containing all the values for LANGUAGE in the LANGUAGES table.

I want to insert the record into students and create record(s) in
STUDENTS_LANGUAGES for each language chosen in the list box. There
could be no language chosen or 1-n language chose.
Any suggestions on how to accomplish this?

Thanks,
Joe

Nov 13 '05 #1
4 1332
You could try something like this (for learning purposes)

Create a new table. In the table design view, add fields, studname,
Lang. In the properties area for each field there are 2 options,
General and Lookup. For the Lang field click on Lookup. In the Display
Control window select List Box. For the Row Source you can add a Select
statement like this:

Select Lang_ID, Language From Languages

In the Column Count field enter 2. For column widths add 0, 1. This
makes the Lang_ID field not visible and only the Language field is
visible. This places a dropdown box in the Lang field when you open the
table. So you could add a student Fred Smith, then when you enter the
Lang field you will get a dropdown arrow with a list of Languages from
the Languages table. Pick a language. The Name of the Language is what
you will see in that field, but when you query the table, you will get
the Lang_ID field. The Lang_ID field is really what gets entered. If
you change the column widths to 1, 1, then the Lang_ID field will also
be visible. If you switch the Select statement to

Select Language, Lang_ID...

The Language field will be the what actually gets written to the Lang
field. You could also just do

Select Language From Languages

If you base a data entry form on this table, you will also have the
dropdown box in the Lang field.

Just some ideas.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2
jv
' first save the student data with something like:
RunCommand acCmdSaveRecord

' next write to the STUDENTS_LANGUAGES table with something like this:
Dim varItm As Variant
For Each varItm In Me!lstLanguages.ItemsSelected
DoCmd.RunSQL "INSERT INTO STUDENTS_LANGUAGES " & _
"(STUDENT_ID, LANG_ID) " & _
"VALUES (" & Me!StudentID & ", " &
Me!lstLanguages.ItemData(varItm) & " )"
Next varItm

'this assumes that STU_LANG_ID is an autonumber field and that
STUDENT_ID and LANG_ID are both numeric fields.
Good Luck

Julie Vazquez

Nov 13 '05 #3
Joe
Thanks to all for replying. It makes sense now and was able to code it
correctly due to the help I received here.

My problems now are:

How to I clear out the list boxes when I move to a new record?

How do I populate the list boxes with the saved results when I come
back to records I previously entered/saved?

Are there any good books on Access 2003/VBA someone can recommend?
Thanks again,
Joe

Nov 13 '05 #4
jv
To clear the list box:
For x = 0 To lstLanguages.ListCount - 1
lstLanguages.Selected(x) = False
Next x

To the repopulate the box:
For x = 0 To lstLanguages.ListCount - 1
If lstLanguages.ItemData(x)= DLookup("LANG_ID",
"STUDENTS_LANGUAGES", "STUDENT_ID=" & me!StudentID)
Then
lstLanguages.Selected(x) = True
End If
Next x

It is probably better to implenent this with a subform.

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: M Wells | last post by:
Hi All, I am developing an Access 2003 project application with the back end in SQL Server 2003. I have a master form that tracks projects, and several subforms on it that track various...
4
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...
2
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...
2
by: Sally | last post by:
I have a simple multiselect listbox with a rowsorce of MemberID, MemberName, SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to Yes when the user selects MemberName? I...
3
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...
2
by: Hey_Moe! | last post by:
I have subform which uses a SQL statement as the record source. One of the criteria (ie. Part of the WHERE condition) is a column value from a ListBox on the MainForm. Two problems exist: 1....
1
by: Helmut Blass | last post by:
hi folks, I have embedded a datasheet as a subform and I want that every time the datasheet is updated, the focus be set on the last record and be visible for the user. that is like simulating...
6
by: AAJ | last post by:
Hi all I have a listbox on a form. If I set its rowsource directly, and the query in the rowsourse returns no data, then the displayed listbox is empty (exactly as you would expect) ...
5
by: lorirobn | last post by:
Hi All, I have a listbox on a main form. When user double-clicks an item in the list box, I move the selected values to a subform at the bottom of the form. List box is not multiselect, and...
7
by: tonsam | last post by:
I am planning to create a form (Issuance) where all the records of the subform will be selected from the listbox. The listbox is not part of the main and subform but will only be visible upon...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.