473,387 Members | 1,606 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,387 software developers and data experts.

Open form using list box (compound key)

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

Mar 2 '06 #1
3 3341
Kaur wrote:
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

Properties to look at are ListIndex, ItemData, Column, ListCount,
Selected, and related properties in online help along with their code
examples.

Here's some example junk code that scans all of the items in a listbox
and updates a record in a table.

Dim intFor As Integer
Dim rst As Recordset
Dim lngKey As Long
Dim blnSelected As Boolean
Set rst = CurrentDb.OpenRecordset("Table", dbOpenDynaset)
For intFor = 1 To Me.ListBox.ListCount - 1
lngKey = Me.ListBox.Column(0, intFor)
blnSelected = Me.ListBox.Selected(intFor)
rst.FindFirst "ID = " & lngKey
If Not rst.NoMatch Then
rst.Edit
ElseIf blnSelected Then
rst.AddNew
rst!ID = lngKey
End If
rst!YesNoField = blnSelected
rst.Update
Next

You'll notice I have the line
For intFor = 1 To Me.ListBox.ListCount - 1
The reason I start at 1 instead of 0 is that I have ListBox headings set
to True. You need to realize that when using ListIndex and ListCount.
Normally you don't process the column headings lines, so normally you
need to ignore them.
Mar 2 '06 #2
If your list box is named lstSurveys and the first column is the Survey
ID and the second column is the Survey Edition ID, then in the double
click event of your listbox you'll need some code like the following:

DoCmd.OpenForm "Form Survey Details", , ,"SurveyID = " &
lstSurveys.Column(0) & " and SurveyEditionID = " & lstSurveys.Column(1)

You may want to include additional code to make sure that an item is
selected in the list or that there are actually items in the list, etc.

See the online help for 'OpenForm Method' and look specifically at the
'WhereCondition' section for more information.

Bruce

Mar 2 '06 #3
Thanks ever so much. I see the mistake in my code based on the code you
wrote. I very much appreciate the help. The form opens up without a
problem.

Kaur

Mar 3 '06 #4

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

Similar topics

4
by: Mark | last post by:
BEGINNER QUESTION I have a table which has a compound primary key consisting of two columns. One of these columns is a foreign key which is generated in another table by an identity. I want...
1
by: P | last post by:
Hi, Access 2002. I am trying to use the PrintOut function to print the current record of the current open form in landscape format to the default Windows printer. Any suggestion on how to set...
3
by: maddman | last post by:
In our database, we have some problem users that think they need to get at the tables themselves rather than use the forms. So I want to keep them from getting to them at all. I've set the DB...
6
by: David W. Fenton | last post by:
I'm generally against using compound keys, except in join tables, but I'm currently mapping out a schema where the join table has child records. The application is for fund-raising and I have four...
5
by: twick10 | last post by:
Hi, I am trying to execute a control method on an open form (not with focus) from a modal dialog box. I want to increment the node selected from the dialog when a certain key is pressed. Any...
14
by: keri | last post by:
Hi, Simple version of the question..... How do I use the where clause of the open form command to show an account with a matching ID to be displayed when the form is opened? Eg. I select a...
8
by: hollinshead | last post by:
Hi there i have bit of an issue. i haver this database that is purely used for searching records under certain criteria. This criteria is chosen by the user on a form using list boxes and combo...
6
by: Palehorse | last post by:
I'd like to apologize upfront for me saying "I'm not a programer", I'm sure you all hear this a hundred times a day. Unfortunately, in this case, it's true. I've been working on trying to figure out...
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: 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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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 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.