Solved

Access 2007 query into textbox

Posted on 2009-03-31
6
752 Views
Last Modified: 2013-11-28
I'm new to Access so i hope this question isn't too basic.
This is basically a modification to the "sales pipeline" database (comes with Access 2007) since it had similarities to what i wanted to write.  I have an access table called "Employees" where there is a field called "comission_rate", which allows me to log each employees commission rate.
I have a second table called "keystoneopportunities" (to log sales opportunity data) where there is a field called "sales1", which documents who the primary salesman is.
On the form "OpportunityInput", which is the input form for a sales opportunity, i have a combobox for the purpose of selecting a salesman.  The control source is "sales1" mentioned earlier.  The rowsource is:

SELECT [Employees Extended].ID, [Employees Extended].[Employee Name] FROM [Employees Extended] ORDER BY [Employees Extended].[Employee Name];

this sets the items i see in the combobox dropdown.

Adjacent to the above combobox where i can select an employee, i would like to have their commission rate (which will be used in some calculations later).  I'm assuming i would place a textbox for this result to be displayed.  Can anyone help me with how to get commission rate to query into this text box?  Also, if the commission rate/% is displayed in a textbox, will it be treated as a number (and not text) so that i can use it in calculations?
0
Comment
Question by:GTC-KTX
  • 2
  • 2
  • 2
6 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 24032589
you can use the following in the afterupdate event of the combo

private sub comboName_afterupdate()

me.text1=cdbl(dlookup("comission_rate","Employees","[ID]= " & me.comboName))

end sub
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 100 total points
ID: 24032598
Add the Commission rate to the combobox row source:

SELECT [Employees Extended].ID, [Employees Extended].[Employee Name],  [Employees Extended].[EmployeeCommissionRate]
FROM [Employees Extended] ORDER BY [Employees Extended].[Employee Name];


Then drop a textbox on the form and set the control source to:

    =YourComboBox.Column(2)

JeffCoachman
0
 

Author Comment

by:GTC-KTX
ID: 24032916
Thanks for both replies.  i didn't really want the commision rates to show up in the combobox, so i tried to implement the first solution (from Capricorn1).  This seems to work fine except when an employee is chosen that doesn't have a commission value in the table.  I get Run-time error  '94' (Invalid use of null).
Any suggestions?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24033176
GTC-KTX,

These are two techniques to do the same thing.

If you set the Column widths property of the combobox, you can hide any column you like.

Jeff
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 400 total points
ID: 24033186
try this

private sub comboName_afterupdate()

me.text1=cdbl(nz(dlookup("comission_rate","Employees","[ID]= " & me.comboName),0)

end sub
0
 

Author Closing Comment

by:GTC-KTX
ID: 31565011
Thanks Guys!  Appreciate the quick response.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now