Woftysofty
New member
- Local time
- Tomorrow, 04:54
- Joined
- Apr 4, 2009
- Messages
- 5
Hi, I am trying to write some code to show or hide some controls on a form depending if the value of another control on same the form is a value in my recordset.
The code I have attempted to develop so far, below, works (kinda), the problem is the cursor in my recordset seems to be stuck on the last record or EOF and does not loop through all my recordset values everytime the code is run. Please help someone.
Private Sub Contact_Name_AfterUpdate()
Dim cnnContactsList As ADODB.Connection
Set cnnContactsList = CurrentProject.Connection
Dim rsContactsList As New ADODB.Recordset
rsContactsList.ActiveConnection = cnnContactsList
rsContactsList.CursorType = adOpenKeyset
rsContactsList.LockType = adLockReadOnly
Dim sqlCntsLst As String
sqlCntsLst = "SELECT [Contacts List].[Contact Name], [Entity Categories].[Entity Category] FROM ([Entity Categories]"
sqlCntsLst = sqlCntsLst & " INNER JOIN [Entity Sub-Categories] ON [Entity Categories].[Entity Category] = [Entity Sub-Categories].[Entity Category])"
sqlCntsLst = sqlCntsLst & " INNER JOIN [Contacts List] ON [Entity Sub-Categories].[Entity ID] = [Contacts List].[Entity Category]"
sqlCntsLst = sqlCntsLst & " WHERE ((([Entity Categories].[Entity Category])='Business'))"
rsContactsList.Open sqlCntsLst
rsContactsList.MoveFirst
Do While Not rsContactsList.EOF
If Me.Contact_Name.Value = rsContactsList(0).Value Then
TradingName_Label.Visible = True
Trading_Name.Visible = True
ACN_Label.Visible = True
ACN.Visible = True
Trading_Name.SetFocus
Else
Internal_Department.SetFocus
TradingName_Label.Visible = False
Trading_Name.Visible = False
ACN_Label.Visible = False
ACN.Visible = False
End If
rsContactsList.MoveNext
Loop
rsContactsList.Close
cnnContactsList.Close
Set rsContactsList = Nothing
Set cnnContactsList = Nothing
End Sub
The code I have attempted to develop so far, below, works (kinda), the problem is the cursor in my recordset seems to be stuck on the last record or EOF and does not loop through all my recordset values everytime the code is run. Please help someone.
Private Sub Contact_Name_AfterUpdate()
Dim cnnContactsList As ADODB.Connection
Set cnnContactsList = CurrentProject.Connection
Dim rsContactsList As New ADODB.Recordset
rsContactsList.ActiveConnection = cnnContactsList
rsContactsList.CursorType = adOpenKeyset
rsContactsList.LockType = adLockReadOnly
Dim sqlCntsLst As String
sqlCntsLst = "SELECT [Contacts List].[Contact Name], [Entity Categories].[Entity Category] FROM ([Entity Categories]"
sqlCntsLst = sqlCntsLst & " INNER JOIN [Entity Sub-Categories] ON [Entity Categories].[Entity Category] = [Entity Sub-Categories].[Entity Category])"
sqlCntsLst = sqlCntsLst & " INNER JOIN [Contacts List] ON [Entity Sub-Categories].[Entity ID] = [Contacts List].[Entity Category]"
sqlCntsLst = sqlCntsLst & " WHERE ((([Entity Categories].[Entity Category])='Business'))"
rsContactsList.Open sqlCntsLst
rsContactsList.MoveFirst
Do While Not rsContactsList.EOF
If Me.Contact_Name.Value = rsContactsList(0).Value Then
TradingName_Label.Visible = True
Trading_Name.Visible = True
ACN_Label.Visible = True
ACN.Visible = True
Trading_Name.SetFocus
Else
Internal_Department.SetFocus
TradingName_Label.Visible = False
Trading_Name.Visible = False
ACN_Label.Visible = False
ACN.Visible = False
End If
rsContactsList.MoveNext
Loop
rsContactsList.Close
cnnContactsList.Close
Set rsContactsList = Nothing
Set cnnContactsList = Nothing
End Sub