Combobox display selection on cliking

Posted on 2002-03-26
Last Modified: 2010-05-02
kcm,i try to include the reference to the database,and it worked,it was able to display the items plus the selction of the combo box items,but when i click on the next and previous buttons ,it displays tiext instead of values on the textbox.
Question by:humbk2002
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 43

Expert Comment

ID: 6896142
You don't need to reopen the database and recordset, if you do then the movenext will not have any effect:

Private Sub NextBtn_Click()
Set DB = OpenDatabase("Z:\Project\FinalProject(ExpensesMonitoringSystem).mdb")
Set RS = DB.OpenRecordset("Expense Category")

Remove these lines and try again.
LVL 44

Expert Comment

ID: 6896218
you are setting Text4 to be values in the recordset fields, but ONLY THE LAST value is actually the one that will be displayed.  Each time you assign a value to a texctbox, THAT value REPLACES (completely replaces) whatever value was there before.

from this code:

Private Sub Form_Load()
Set DB = OpenDatabase("Z:\Project\FinalProject(ExpensesMonitoringSystem).mdb")
Set RS = DB.OpenRecordset("Expense Category")
Combo1.AddItem "Telephone Bills"
Combo1.AddItem "Transportation"
Combo1.AddItem "Electricity Bills"
Combo1.AddItem "Payroll Bills"
Combo1.AddItem "Stationery"
Text4.Text = RS!Payroll
Text4.Text = RS!TelephoneBill
Text4.Text = RS!Transportation
Text4.Text = RS!ElectricityBill
Text4.Text = RS!Stationery
Call List1.AddItem("Date : " & Date)
Call List1.AddItem("Time : " & Time)
End Sub

Text4 will end up with ONLY the value from

Text4.Text = RS!Stationery

the preceding 4 lines are TOTALLY USELESS, and accomplish ABSOLUTELY nothing.

What are you trying to show in Text4? (by the way, it is a very GOOD idea to name text boxes for what they are REALLY showing, rather than to use the default name that Access assigns to them. So is Text4 showing an Amount?, then name it txtAmount.  That way you program has some sembelance of readability, and you do not need to remember what Text4 is used for.)


Expert Comment

ID: 6896387
HI humbk2k2

pls Try out this code
open the Recordset in the Formload event.

Dim strFldName as String

Private Sub Form_Load()
Set DB = OpenDatabase("Z:\Project\FinalProject(ExpensesMonitoringSystem).mdb")
Set RS = DB.OpenRecordset("Expense Category")
Combo1.AddItem "Telephone Bills"
Combo1.AddItem "Transportation"
Combo1.AddItem "Electricity Bills"
Combo1.AddItem "Payroll Bills"
Combo1.AddItem "Stationery
End Sub

Private Sub Combo1_Click()
strFldName = Combo1.List(Combo1.ListIndex)
Text4.Text = FillTextValue(strFldName)
End Sub

Private Sub cmdPrev_Click()
if not rs.BOF then
  text4.Text = strFldName
  Msgbox "Beginning of File reached"
end if
End Sub

Private Sub cmdNext_Click()
if not rs.EOF then
  text4.Text = strFldName
  Msgbox "End of File reached"
end if
End Sub

Private Function FillTextValue(strVal as String) as String
Select Case strVal
    Case "Telephone Bills"
        FillTextValue = rs("TelephoneBill")
    Case "Transportation"
        FillTextValue = rs("Transportation")
    Case "Electricity Bills"
        FillTextValue = rs("ElectricityBill")
End Select
End function


MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.


Author Comment

ID: 6898808
kcm76,your code there is an error message thats displayed when i try to make a selection on the combo box items.
There is a compilation error thus:

"ByRef argument type mismatch.:

Remember i want to get the infomation to be displayed on the textbox to come from a database,and the figure to be displayed on the textbox(text4),has to be displayed whenever i make a selection on the combobox,afters selecting,the next button and the previous buttons should allow me to go from one item to another on the list.

Expert Comment

ID: 7017042
10 open questions, many are far below the minimum for easy questions of 50 points.  The maximum per question is 500 points.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link 
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange
LVL 16

Expert Comment

ID: 7754732

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- refund/PAQ
Please leave any comments here within the
next seven days.

Accepted Solution

SpideyMod earned 0 total points
ID: 7811556
per recommendation

Community Support Moderator @Experts Exchange

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question