Ok, I got a tickler for your brains. I am converting a program I wrote in VB6 to Visual Studio 2010 VB.Net and have run into a problem. I am trying to cycle through 20 form elements on a form that all have the prefix ‘chkCustomerItems’ and then have a number 1 to 20 behind them. I am using this with a database lookup so that it there is a database entry it then applies the database item name to the checkbox’s text field and turns visibility on. Here is the code I wrote:
ConnOpenClose()
Rs = New ADODB.Recordset
Sql = "SELECT * FROM CustomersItems;"
Rs.Open(Sql, Conn)
If Rs.EOF = False Then
tempInteger = 1
Rs.MoveFirst()
Do
tempString = "chkCustomerItems" & tempInteger.ToString
Me.Controls(tempString).Text = Rs.Fields("Item").Value
Me.Controls(tempString).Visible = True
tempInteger = tempInteger + 1
Rs.MoveNext()
If tempInteger = 21 Then GoTo ExitLoop
Loop Until Rs.EOF
ExitLoop:
End If
When it runs, I get a NullReferenceException error. This is basically the code that I used in VB6 (with some changes for .NET infrastructure). Help me please figure out what I am doing wrong, for the time being I am having to hard code all 20 items in, and while it works, it doesn’t look nor run pretty.
Thank you in advance
you are using Text property so i assume that this is textbox.
try this: