Solved

Showing a textbox based on a query result

Posted on 2011-03-23
6
235 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
Industry Leaders: 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!

 
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

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.

Question has a verified solution.

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

Suggested Solutions

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

679 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