Link to home
Start Free TrialLog in
Avatar of humbk2002
humbk2002

asked on

Combobox display selection on cliking

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.
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
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.)

HI humbk2k2


pls Try out this code
open the Recordset in the Formload event.
DO NOT REOPEN IT AGAIN IN CMD_NEXT OR CMD_PREV 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
  rs.MoveNext
  text4.Text = strFldName
else
  Msgbox "Beginning of File reached"
end if
End Sub



Private Sub cmdNext_Click()
if not rs.EOF then
  rs.MoveNext
  text4.Text = strFldName
else
  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

ALL THE BEST

KCM
Avatar of humbk2002
humbk2002

ASKER

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.
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.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

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.
https://www.experts-exchange.com/questions/Q.20283897.html
https://www.experts-exchange.com/questions/Q.20273817.html
https://www.experts-exchange.com/questions/Q.20274315.html
https://www.experts-exchange.com/questions/Q.20275778.html
https://www.experts-exchange.com/questions/Q.20277334.html
https://www.experts-exchange.com/questions/Q.20278207.html
https://www.experts-exchange.com/questions/Q.20281536.html
https://www.experts-exchange.com/questions/Q.20284857.html
https://www.experts-exchange.com/questions/Q.20285984.html
https://www.experts-exchange.com/questions/Q.20287484.html



*****  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
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://www.experts-exchange.com/commspt/Q.20277028.html
 
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.
Moondancer
Moderator @ Experts Exchange
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

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.
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial