Solved

Showing a textbox based on a query result

Posted on 2011-03-23
6
244 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 500 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

Independent Software Vendors: 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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

634 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