• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • Last Modified:

Populate form based on a text box

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
zafridi
Asked:
zafridi
3 Solutions
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
messen1975Commented:
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
 
GRayLCommented:
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
zafridiAuthor Commented:
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
 
GRayLCommented:
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
 
zafridiAuthor Commented:
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
 
GRayLCommented:
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now