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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing text box using query result!!!

Status
Not open for further replies.

MikeDNova

Programmer
Jul 3, 2002
86
US
hey guys,

i'm trying to retrieve the text from a textbox, search for a substring within that text, and then replace it with another substring that is the result of a query.

for example i'm trying to replace: "the bear climbed up the @123" with "the bear climbed up the mountain"

i am now getting an "argument not optional" error
i'm not sure where to go from here....

here is my code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If (Me.txtSentence.Text <> &quot;&quot;) Then
Dim db As Database
Dim qdef As QueryDef
Dim rs As Recordset

Dim question As String
Dim priority As String
Dim varPriority As String
Dim sentence As String
Dim myPos As Integer
sentence = Me.txtSentence.Text

myPos = InStr(sentence, &quot;@&quot;)
priority = Mid(sentence, myPos, 5)
varPriority = Mid(priority, 2, 4)


Set db = CurrentDb()
Set qdef=db.QueryDefs&quot;qrybasInspectionResponsePrioritySelPrm&quot;)
qdef.Parameters(&quot;pPriority&quot;) = varPriority


Set rs = qdef.OpenRecordset()
question = rs.FindFirst

Me.Report.txtSentence.Text = Replace(sentence, priority, question)
End If
End Sub

any help would be greatly appreciated!!!
thanks in advance!!
-mike
mikednova@hotmail.com
 
ok, i narrowed it down to this line of code:
question = rs.FindFirst

now the query should have only returned one field in the recordset. how do i access this field?
 
ok, i narrowed it down to this line of code:
question = rs.FindFirst

now the query should have only returned one field in the recordset. how do i set it equal to question?
 
ok got it.
question = rs(&quot;question&quot;)

now a new problem with this line of code...

Me.txtSentence.Text = Replace(Sentence, priority, question)

it says i can't reference a property or method for a control unless the control has the focus....

how do i get around this???
anybody out there???
 
Put a

txtSentence.SetFocus

before you try to change its text.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top