Solved

Showing a textbox based on a query result

Posted on 2011-03-23
6
198 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
  • 3
  • 2
6 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility

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 39

Expert Comment

by:als315
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
It is a number field, the textbox that houses the customer number is CustNumTextBox
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

772 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

11 Experts available now in Live!

Get 1:1 Help Now