Open form using list box selection (compound key)

K

Kaur

Hi,

I have a form that has a list box (unbound) which lists all the survey
names. the data is retrieved from Survey table that is made of compound

key SurveyID and SurveyEditionID (both number fields). The list box
displays both the fields. Could some one help me with the code where if

I double click on one of the records in the list box and a second form
(Form Survey Details) opens up showing the details of the same survey
and survey Edition selected in previous form. I am pretty new to
developing the Access forms.


Any help would be appreciated.


Thanks


Kaur
 
G

Guest

A little more information, if you don't mind...

Your primary form (the one with the list box), after a list item is
selected, populates other fields on the form with information from the Survey
table?

If this is the case, why not simply add a button that will open the second
form?

Sharkbyte
 
G

Guest

It sounds like what you want to do is have a button that will open a new form
(the one with the survey data) based on which survey you have selected in
your list box.

So, your code would be something like:

Private Sub lstListbox_DblClick() (Or btnListbox_Click, if you decide to
use a button)

If lstListbox.Value = "Survey1" Then
DoCmd.OpenForm "Survey1"
End If

End Sub

If you need to go to a specific record, try using either GoToRecord or
FindRecord. You should be able to either define a global variable or pass
the record ID to the new form using OpenArgs().

Hope that helps.

-Chris
 
K

Kaur

My first form lists all the surveys with survey edition number as a
compound key retreived from table Surveys (Table surveys consist of
SurveyID and SurveyEditionID as compound key). The second form opens up
the details of survey (Survey Question, respondent, percentage etc) for
each survey and survey edition number retrieved from table Survey
responses. To open the second form by clicking on a button from form1
this is the code I am writing which is giving me an error. Basically I
donot know how to handle the compound key (SurveyId, SurveyEditionID)
in the list box to open the form 2 with same surveyID and survey
Edition ID.

Private Sub ShowRecord_Click()
'Find a selected record, then close the search dialog box

DoCmd.OpenForm "frmQuestion", , , _
"tblSurveyEditions.SurveyID =" & Me.lstSearch And
"tblSurveyEditions.SurveyEditionID =" & Me.lstSearch.Column(2)
'Close the dialog box
DoCmd.Close acForm, "frmListBoxSearch"

End Sub

The error is type mismatch.

Any help would be appreciated.
 
K

Kaur

Thanks ever so much for all the help. I found the error in my code. It
runs fine now
Kaur
 

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