Code:
Public Sub CreateNewPersonRestrictions()
Dim cmd As New SqlCommand
Dim conn As New SqlConnection
'Declare datareader
Dim NewPersonRestrictionDataReader As SqlDataReader
'to initalize the connection of datareader to demograchics
conn.Open() --error here
NewPersonRestrictionDataReader = cmd.ExecuteReader
Try
' Get Logged-in User Name and the CreateNewPersonValue
Dim ctUser As New sqlctDemographics.ctDemographics
Dim NewPerson As Boolean
Dim ctr As Control
NewPersonRestrictionDataReader = ctDemographics.GetCreateNewPersonRestrictions 'Changed ctUser.GetCreateNewPersonRestrictions
' check whether there's a Record
If NewPersonRestrictionDataReader.Read Then 'reading first (and only) record
'Set the datareader create newperson value to the newperson variable
NewPerson = NewPersonRestrictionDataReader.Item("CreateNewPerson")
'Check the new person value
If NewPerson = False Then
'The value is false, disable the buttons in the startup form.
For Each ctr In CallingForm.Controls
If ctr.Name = "btnNewEntry" = True Then
ctr.Enabled = False
End If
If ctr.Name = "btnNewNonSSNEntry" = True Then
ctr.Enabled = False
End If
Next
End If
End If
Catch ex As Exception
MsgBox(ex)
'close the username data reader
NewPersonRestrictionDataReader.Close()
Finally
' close the datareaders in case they're still open
If Not (NewPersonRestrictionDataReader Is Nothing) Then
NewPersonRestrictionDataReader.Close()
End If
End Try
End Sub
Comment