Populating a form..

T

thewabit

Hello,

I am VERY new at access so please be gentle.

I am trying to populate a form with table data that is linked to a selected
item presented in a list box. Each of the items in the list box have data
stored in a table. I am looking for maybe some VB that when that item is
highlighted and a button at the bottom is pushed, it opens another form and
the table data is displayed. To complicate things, the form I want to open up
have a subform as well.

PLEASE help!

Thanks!
 
J

John W. Vinson

Hello,

I am VERY new at access so please be gentle.

I am trying to populate a form with table data that is linked to a selected
item presented in a list box. Each of the items in the list box have data
stored in a table. I am looking for maybe some VB that when that item is
highlighted and a button at the bottom is pushed, it opens another form and
the table data is displayed. To complicate things, the form I want to open up
have a subform as well.

PLEASE help!

Thanks!

I'm *guessing* here... because you really have not posted any details about
your table, listbox, or form... but I think you can use either of two
solutions:

1. Base the form you want to open on a Query referencing the listbox as a
criterion:

=[Forms]![FirstFormName]![Listboxname]

The VBA would be very simple, just opening the form; the Command Button Wizard
will give "open a form" as an option.

2. Use the command button wizard to create an Open Form button. Edit the code
from (something like)

Private Sub cmdOpenIT_Click()
On Error GoTo Err_cmdOpenIT_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourFormName"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenIT_Click:
Exit Sub

Err_cmdOpenIT_Click:
MsgBox Err.Description
Resume Exit_cmdOpenIT_Click

End Sub

by adding just one line before the DoCmd.OpenForm:

stLinkCriteria = "[fieldname] = " & Me!listboxname

where the fieldname is the field in the form's recordsource which matches the
listbox value you're searching.

Use

stLinkCriteria = "[fieldname] = '" & Me!listboxname & "'"

if it's a Text field.
 
T

thewabit via AccessMonster.com

John,

Thank you very much! Please stay with me on this thread if you would.

I have learned some more about this situation and will try to explain it.

The item selected from the list box is querying a table ("tbl_template"),
specifically "ID" and "Name". Each ID has 3 subtables. The form
("Questionaire_template") that needs to be populated with data selected in
the list box is made up of a form and 2 subforms. Each of the 3 forms in
"Questionaire_template" correspond with the 3 subtables that is needed to
fill the "questionaire_template".

Does this change things? I told you I was VERY new.
[quoted text clipped - 10 lines]

I'm *guessing* here... because you really have not posted any details about
your table, listbox, or form... but I think you can use either of two
solutions:

1. Base the form you want to open on a Query referencing the listbox as a
criterion:

=[Forms]![FirstFormName]![Listboxname]

The VBA would be very simple, just opening the form; the Command Button Wizard
will give "open a form" as an option.

2. Use the command button wizard to create an Open Form button. Edit the code
from (something like)

Private Sub cmdOpenIT_Click()
On Error GoTo Err_cmdOpenIT_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "YourFormName"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenIT_Click:
Exit Sub

Err_cmdOpenIT_Click:
MsgBox Err.Description
Resume Exit_cmdOpenIT_Click

End Sub

by adding just one line before the DoCmd.OpenForm:

stLinkCriteria = "[fieldname] = " & Me!listboxname

where the fieldname is the field in the form's recordsource which matches the
listbox value you're searching.

Use

stLinkCriteria = "[fieldname] = '" & Me!listboxname & "'"

if it's a Text field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top