Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Populate form based on a text box

Posted on 2007-11-28
7
Medium Priority
?
585 Views
Last Modified: 2008-11-12
Hi Experts-

I have a form with in access which is pulling data from Ms Sql thru ODBC connection (a View). What i want is to have a text box as a search field where the user types in a number or part of a number and it will only display the relevant results in the form. I have done this before with a combo box but not with text box. What i have is right now when i open the form it pops up  a dialog saying enter parameter value (which is my text box used for searching) then i put in some number and it displays the info on the form. What i want to do is to be able to go directly to the form where i have the text box. i put in the number there and gives me the results and then i should be able to look up for another number. On my form record source i have the following query

SELECT * FROM myview WHERE Num=txtSearch.value or right(Num,5)=txtSearch.value; and the other text boxes where i see the results they all have their control source set to the respective fields(columns) of the view.  Any kind of help would be appreciated. Thanks
0
Comment
Question by:zafridi
[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
7 Comments
 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 120 total points
ID: 20367491
Just reset the RecordSource of your form when you need to search ... for example, if you have a Search button, and want to refer to a textbox:

Sub cmdSearch_Click()
  Me.Recordsource = "SELECT * FROM myview WHERE Num=" & txtSearch & " OR right(Num,5)=" & txtSearch.value
End Sub

This assumes Num is a numeric field; if not, then you'd need to surround it with single quotes.
0
 
LVL 6

Assisted Solution

by:messen1975
messen1975 earned 120 total points
ID: 20367497
Delete the Form Source from the Form Source box
In the properties for your Textbox create an After  Update Event for your textbox

Set the  After Update Event to

Me.Form.RecordSource = SELECT * FROM myview WHERE Num=txtSearch.value or right(Num,5)=txtSearch.value
Me.Form.Refresh


0
 
LVL 44

Accepted Solution

by:
GRayL earned 135 total points
ID: 20367551
If your form now provides the parameters pop-up box, all you need do is place the textbox on the form, and replace the parameters portion of the query behind the form with the textbox reference:
From:

Select * from myView where Num = [EnterNum];

to:

Select * from myView where Num = Forms!myFormName!txtSearch

Now when you open the form the textbox is empty so the form should be clear.  Now when you place a value in the textbox you want the form to re-query so add this code to the AfterUpdate event of the textbox:

Private Sub txtSearch_AfterUpdate()
  Me.requery
End Sub
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:zafridi
ID: 20369202
none of the above works for me...i guess u guys didn't quite get what i was looking for...simply put if i want to display values in a form(in text boxes) based on another text box that exists on the same form..how is it get done.. or i could have a subform that displays the results based on a textbox (exists on another form)..i think it should be pretty simple..i've done this before from a combo box but couldnt get it done from a text box..im not sure why. i hope i explained my question properly..thanks
0
 
LVL 44

Expert Comment

by:GRayL
ID: 20369266
Do you now have a form, based on a parameter query which asks for a value for Num?  That's certainly what your question reads like.   On that same form you create a textbox named txtSearch, correct?.  You modified the query, and inserted the code? What happened when you ran my answer?
0
 

Author Comment

by:zafridi
ID: 20369440
This is what i have in the form record source now

SELECT * FROM dbo_EquipmentforAccessVw WHERE EquipSerialNum=Forms!frmSearchOptions!txtSearchVin;

and the text box after update event  Me.Requery

when i run it..the form opens but nothing shows...its just blank...not even the labels..no text nothing...thankss
0
 
LVL 44

Expert Comment

by:GRayL
ID: 20369835
I see the problem.  An Access ODBC connection to a SQL table is processed in the SQL server.  It knows nothing about the local Access Form.  Somehow you have to get the value from the local form textbox control into something understood by the SQL parser - @varvalue ??
0

Featured Post

Technology Partners: 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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

618 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