Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting New Characters typed as you type them.

Status
Not open for further replies.

pcdaveh

Technical User
Sep 26, 2000
213
0
0
US
Situation: I have a form with a text box that I want the user to type into. I need to detect the characters as they are being typed into the text box. Then execute some other code such as passing the text in the text box into a variable and then passing the variable into a SQL statement that is embedded in the code. What event has to be used? Here is some sample code that doesn't work because I can't figure out which event to use.



Dim myvar As String
Dim strSQL As String
Dim strLastName As String

strLastName = txtLast_Name.Value

strSQL = "SELECT dbo.CONTACT1.KEY4, dbo.CONTACT2.UMAINFNAME, dbo.CONTACT1.LASTNAME, dbo.CONTACT1.ADDRESS1, dbo.CONTACT1.CITY, "

strSQL = "SELECT dbo.CONTACT1.LASTNAME, dbo.CONTACT2.UMAINFNAME, dbo.CONTACT1.ADDRESS1, dbo.CONTACT1.CITY, dbo.CONTACT1.STATE, "
strSQL = strSQL & "dbo.CONTACT1.ZIP, dbo.CONTACT1.KEY4, dbo.CONTACT1.ADDRESS2, dbo.CONTACT1.ADDRESS3, dbo.Personnel.Personnel_Username, "
strSQL = strSQL & "dbo.Personnel_Groups.[Group] "
strSQL = strSQL & "FROM dbo.Personnel_Linking INNER JOIN "
strSQL = strSQL & "dbo.Personnel_Groups ON dbo.Personnel_Linking.Group_ID = dbo.Personnel_Groups.Group_ID INNER JOIN "
strSQL = strSQL & "dbo.Personnel ON dbo.Personnel_Linking.Personnel_ID = dbo.Personnel.Personnel_ID INNER JOIN "
strSQL = strSQL & "dbo.CONTACT1 INNER JOIN "
strSQL = strSQL & "dbo.CONTACT2 ON dbo.CONTACT1.ACCOUNTNO = dbo.CONTACT2.ACCOUNTNO ON dbo.Personnel_Groups.[Group] = dbo.CONTACT1.KEY4 "
strSQL = strSQL & "WHERE (dbo.Personnel.Personnel_Username = N'dharris') AND (dbo.CONTACT1.LASTNAME LIKE '" & strLastName & "%') "
strSQL = strSQL & " ORDER BY dbo.CONTACT1.LASTNAME, dbo.CONTACT2.UMAINFNAME "
 
Hi, what I did is I put the code in the "on click" event of my preview report command button. So first I created the strSQL string then I ran it

DoCmd.RunSQL strSQL

this works if your SQL in a maketable one and the report is based on that new table.

If it's not a maketable I think is like

Dim qdf As QueryDef
Set qdf = dbf.CreateQueryDef("MyQuery", strSQL)

and your report is based on MyQuery query.

Even if you don't wnat to run a report from that data I hope the above will help. (putting your code in the onclick event of a command button.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top