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


Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.


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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

691 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