Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Showing a textbox based on a query result

Posted on 2011-03-23
6
Medium Priority
?
253 Views
Last Modified: 2012-05-11
I have an access table that holds customer information and another table that holds orders associated with those customers.  I want to place a textbox on the form that is used to enter customer information that alerts the salesperson if there is an order associated with that customer based on matching a customer number between those two tables.  So, if there are no orders the textbox is blank, but if there are turn it red and display some text.  If there are orders I want to show a button that I will use to open a form to show those orders.

I know enough about access to create the queries and forms and such, but I don't know how to change the behaviour of a textbox based on the results of a query.

0
Comment
Question by:dgooge
[X]
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
  • 3
  • 2
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35198925

you can use dlookup() or dCount() functions to check if records exists for a customer..

in the afterupdate event of the textbox where you enter customer number

private sub txtcustomer_afterupdate()
if dcount("*","tableName","customernumber =" & me.txtcustomer)>0 then
  me.YourNEWTextbox.backcolor=vbred

end if

end sub
0
 
LVL 40

Expert Comment

by:als315
ID: 35198931
You can use dlookup for searching records for this customer and if returned falue (records count, for example) >0 set text and color of textbox
0
 

Author Comment

by:dgooge
ID: 35198963
We're getting closer, the customer number will already be on the form where the alert will be shown ( I know I said textbox in my first post, but I don't know what is more appropirate to show an alert, a textbox or a label) , tblCustomer.CustomerNumber is the field name.  I need to match that with tblOrders.CustomerNumber.  I have very little experience with VBA, so I need a bit more handholding.
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 35198991
is CustomerNumber field Text Or Number data type?
what is the name of the textbox for the CustomerNumber?

a label or textbox will do.
0
 

Author Comment

by:dgooge
ID: 35199025
It is a number field, the textbox that houses the customer number is CustNumTextBox
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 35199096
place this code in the afterupdate event of CustNumTextBox


private sub CustNumTextBox_afterupdate()
if dcount("*","tblOrders","customernumber =" & me.CustNumTextBox)>0 then
  me.YourNEWTextbox.backcolor=vbred
  else
   me.YourNEWTextbox.backcolor=vbwhite
end if

end sub

Open in new window


place this codes in the current event of the form

private sub form_current()

if dcount("*","tblOrders","customernumber =" & me.CustNumTextBox)>0 then
  me.YourNEWTextbox.backcolor=vbred
  else
   me.YourNEWTextbox.backcolor=vbwhite
end if


end sub

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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