Solved

Showing a textbox based on a query result

Posted on 2011-03-23
6
229 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 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

860 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