Writing =Dlookup() into TextBox.RecordSource using VB at run time.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the problem:
Access rejected quotes inside Dlookup() and Char "=". So I have changed them
for Chr(34) and Chr(61). Now there is no syntax error in thee code, but
control does not accept ControlSource from VB.
Is there a way to write Dlookup() into ComtrolSource Attribute like other
functions which I used to write from VB?
Thanks in advance.
 
Ilya,

Me.MyControl.ControlSource =
"=DLookup('[MyField]','MyTable','<MyCriteria>')"
 
Dear Steve:
I did the way you suggest also. How you would suggest manage this:
RecordSource = "=DLookUp("VALUE","Qry_Sel_Value_PerOwnerCat_Txbl","SSN=" &
"'" & [Forms]![CLIENTCURRPROFILE].[TxtSSN] & "'" & " And CAT=" & "'" &
[Forms]![CLIENTCURRPROFILE].[TxtCatCode] & "'")".
Access does not allow to use single qquote in my case because it has dual
meaning.
So I used Chr(34) and Chr(44) . No syntax errors, but Control rejects this
entry and other controls stop working.
Please, Help.
Steve Schapel said:
Ilya,

Me.MyControl.ControlSource =
"=DLookup('[MyField]','MyTable','<MyCriteria>')"

--
Steve Schapel, Microsoft Access MVP

I have the problem:
Access rejected quotes inside Dlookup() and Char "=". So I have changed them
for Chr(34) and Chr(61). Now there is no syntax error in thee code, but
control does not accept ControlSource from VB.
Is there a way to write Dlookup() into ComtrolSource Attribute like other
functions which I used to write from VB?
Thanks in advance.
 
Ilya,

I assume you mean ControlSource not RecordSource?

I would personally avoid this conundrum by putting the form references
directly into the criteria of the Qry_Sel_Value_PerOwnerCat_Txbl query,
rather than trying to manage them within the DLookup. But I think the
following will work for your purposes...
"=DLookup('[VALUE]','Qry_Sel_Value_PerOwnerCat_Txbl','[SSN]=" & """" &
[Forms]![CLIENTCURRPROFILE].[TxtSSN] & """" & " And CAT=" & """" &
[Forms]![CLIENTCURRPROFILE].[TxtCatCode] & """" & "')"
 
Back
Top