473,403 Members | 2,323 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,403 software developers and data experts.

list box probs

10
I need help here...
I have created a list box (LstCName) from a form named (contactlist) that picks up employee names from a query named (lkpcontacts). The employee names are displayed fine but when i click on a name, i want it to take me to that persons details which are stored in (frmcontacts). At the moment it's not doing it... can you help.




Private Sub LstCName_DblClick(Cancel As Integer)
' Double-clicking a name is the same as choosing the name
' and then clicking the edit button.
cmdSome_Click
End Sub

Private Sub cmdSome_Click()
Dim strWhere As String, varItem As Variant
' Request to edit items selected in the list box
' If no items selected, then nothing to do
If Me!LstCName.ItemsSelected.Count = 0 Then Exit Sub
' Loop through the items selected collection
For Each varItem In Me!LstCName.ItemsSelected
' Grab the ContactID column for each selected item
strWhere = strWhere & Me!LstCName.Column(0, varItem) & ","
Next varItem
' Throw away the extra comma on the "IN" string
strWhere = Left$(strWhere, Len(strWhere) - 1)
' Open the contacts form filtered on the selected contacts
strWhere = "[ContactID] IN (" & strWhere & ") "
DoCmd.OpenForm FormName:="frmContacts", WhereCondition:=strWhere
DoCmd.Close acForm, Me.Name

End Sub
Nov 2 '06 #1
7 1686
VALIS
21
I need help here...
I have created a list box (LstCName) from a form named (contactlist) that picks up employee names from a query named (lkpcontacts). The employee names are displayed fine but when i click on a name, i want it to take me to that persons details which are stored in (frmcontacts). At the moment it's not doing it... can you help.




Private Sub LstCName_DblClick(Cancel As Integer)
' Double-clicking a name is the same as choosing the name
' and then clicking the edit button.
cmdSome_Click
End Sub

Private Sub cmdSome_Click()
Dim strWhere As String, varItem As Variant
' Request to edit items selected in the list box
' If no items selected, then nothing to do
If Me!LstCName.ItemsSelected.Count = 0 Then Exit Sub
' Loop through the items selected collection
For Each varItem In Me!LstCName.ItemsSelected
' Grab the ContactID column for each selected item
strWhere = strWhere & Me!LstCName.Column(0, varItem) & ","
Next varItem
' Throw away the extra comma on the "IN" string
strWhere = Left$(strWhere, Len(strWhere) - 1)
' Open the contacts form filtered on the selected contacts
strWhere = "[ContactID] IN (" & strWhere & ") "
DoCmd.OpenForm FormName:="frmContacts", WhereCondition:=strWhere
DoCmd.Close acForm, Me.Name

End Sub
Doesn't Me refer to the current object executed?
If so you'd be opening and closing the form almost instantaneously?
What happens if you step through the code?
Nov 2 '06 #2
NeoPa
32,556 Expert Mod 16PB
You're missing the quotes around the items in the IN() list in the WHERE clause.
The particular line should read :-
Expand|Select|Wrap|Line Numbers
  1. strWhere = strWhere & "'" & Me!LstCName.Column(0, varItem) & "',"
Nov 2 '06 #3
NeoPa
32,556 Expert Mod 16PB
Doesn't Me refer to the current object executed?
No, Me refers to the object in which the code has scope.
In this case, the owning form, or the form which is the parent of the object that this code is related to (LstCName).
Nov 2 '06 #4
dlowry
10
Appreciate your help.... from what you've given me it now opens the form fine.....but no data within. Any ideas ?
Nov 2 '06 #5
NeoPa
32,556 Expert Mod 16PB
Appreciate your help.... from what you've given me it now opens the form fine.....but no data within. Any ideas ?
Can't help without any idea of what data is being processed; what is in the list box etc.
Nov 2 '06 #6
dlowry
10
i'll keep it simple for now...

ContactID
FirstName
LastName
Nov 2 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
I need help here...
I have created a list box (LstCName) from a form named (contactlist) that picks up employee names from a query named (lkpcontacts). The employee names are displayed fine but when i click on a name, i want it to take me to that persons details which are stored in (frmcontacts). At the moment it's not doing it... can you help.
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub LstCName_DblClick(Cancel As Integer)
  3. ' Double-clicking a name is the same as choosing the name
  4. ' and then clicking the edit button.
  5.  
  6. cmdSome_Click
  7.  
  8. End Sub
  9.  
  10. Private Sub cmdSome_Click()
  11. Dim strWhere As String
  12. Dim varItem As Variant
  13.  
  14. strWhere = "" ' initialise the variable
  15. ' Request to edit items selected in the list box
  16. ' If no items selected, then nothing to do
  17. If Me!LstCName.ItemsSelected.Count = 0 Then Exit Sub
  18.  
  19. ' Loop through the items selected collection
  20. For Each varItem In Me!LstCName.ItemsSelected
  21. ' Grab the ContactID column for each selected item
  22. 'assuming ContactID is a number and not a string and ContactID is the bound column
  23.     strWhere = strWhere & "[ContactID]=" & Me!LstCName.ItemData(varItem) & " OR "
  24. Next varItem
  25.  
  26. ' Throw away the " OR " in the string
  27. strWhere = Left(strWhere, Len(strWhere) - 4)
  28.  
  29. ' Open the contacts form filtered on the selected contacts
  30.  
  31. DoCmd.OpenForm "frmContacts", , , strWhere
  32. DoCmd.Close acForm, Me.Name
  33.  
  34. End Sub
  35.  
  36.  
Just a note...

Has the form "frmContacts" already got a where statement in its record source ?
Nov 7 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Arijit Chatterjee | last post by:
Hi Everybody, I am facing another probs. I have created a trigger for table Tab1 for perticular column col1 for checking value ranges.But at time for using insert statement it is working fine but...
6
by: massimo | last post by:
Hey, I wrote this program which should take the numbers entered and sort them out. It doesnąt matter what order, if decreasing or increasing. I guess I'm confused in the sorting part. Anyone...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
24
by: Robin Cole | last post by:
I'd like a code review if anyone has the time. The code implements a basic skip list library for generic use. I use the following header for debug macros: /* public.h - Public declarations and...
4
by: JS | last post by:
I have a file called test.c. There I create a pointer to a pcb struct: struct pcb {   void *(*start_routine) (void *);   void *arg;   jmp_buf state;   int    stack; }; ...
2
by: andrewcw | last post by:
Seems it should be simple. I had problems with a larger class and the newsgroup suggested something I also tried. So I pruned my class to see if I could find out what could be wrong, Still dont...
7
by: polecat | last post by:
Im new to .NET and I am having probs with this Every time I reload the form the same data is repeated again.... Done reading on msdn and another forum cant figure out why the...
0
by: bkpatel | last post by:
get Join the PHP community and share ur probs - soln <table border=0 style="background-color: #fff; padding: 5px;" cellspacing=0> <tr><td> <img...
2
by: brettokumar | last post by:
hai im storing value in cookies. if my 2nd value or 3rd value is stored means my previous cookies are expired my current cookies only stored others cookies values will be null how to i solve...
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...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.