Using Variables to assign a value to a textbox

A

advertising

Hello,

I am trying to assign a value to a textbox on the form.
Both the value and the textbox names are passed as variables.

I am calling a public sub which populates the textbox on the form, but
I am getting nowhere.

The code I am currently using is:

Public Sub KeywordReplace(ByVal strfieldname As String, ByVal
strKeyword As String)
'This is the textbox fieldname
frm.ActiveControl.Name =strfieldname
'This is the value to populate the textbox
frm.ActiveControl.Text = strKeyword
End Sub

I have tried other combinations, but haven't got anywhere. The code is
VB.NET.

Please could someone help.

Thanks in Advance,
Dean Richardson
 
A

advertising

Hi,

Thanks for that. I am getting a error that says Name 'FindControl' is
not declared. Is there something I need to declare/include to get this
function recognised. The project is a VB.NET windows application.

Thanks,

Dean
 
A

advertising

Hi,

Its working now - i forgot to add the parent:

Dim c = Me.Parent
Dim ctl As Control = c.FindControl(strfieldname)

I'm now getting the same runtime error message that I got before:

NullReferenceException was unhandled
Object variable or With block variable not set.

Could anyone help me with this?

Thanks,
Dean
 
A

advertising

Hi,

Finally worked it out:

c=form.parent

For Each ctl In c.Controls
If ctl.Name = strfieldname Then
ctl.Text = strKeyword
End If
Next

Thanks,
Dean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top