DevastatioN
Registered User.
- Local time
- Today, 09:21
- Joined
- Nov 21, 2007
- Messages
- 242
Hello,
Just a quick question because I am unsure of the technical specifications of each. Which is faster to lookup quick information, a DLookup or a Recordset. I have security built into the form to check the username, and show options appropriately.
I originally made the code using recordset and planned to migrate it to DLookup after the prototype was complete, but am wondering which is faster now. Here is the example code:
Recordset:
DLookup:
Just a quick question because I am unsure of the technical specifications of each. Which is faster to lookup quick information, a DLookup or a Recordset. I have security built into the form to check the username, and show options appropriately.
I originally made the code using recordset and planned to migrate it to DLookup after the prototype was complete, but am wondering which is faster now. Here is the example code:
Recordset:
Code:
'Set the form based on user rights and privileges
Dim username As String
Dim leftTop As Integer
'This is the height on the form of the top buttons
leftTop = 496
'Lookup the current user logged in
username = DLookup("[LoggedIn]", "[tblCurrentUser]")
'If the user is supposed to have the Add/Edit Items button, show the button and place at leftTop
If DLookup("[AddEditFileButton]", "[tblUsers]", "[UserID]='" & username & "'") = -1 Then
Me.btnAddEditItems.Visible = True
'Set leftTop for next button in list
leftTop = leftTop + 480
Else
Me.btnAddEditItems.Visible = False
End If
'Set the other buttons accordingly
Me.btnViewItems.Top = leftTop
leftTop = leftTop + 480
Me.btnOverdueItems.Top = leftTop
leftTop = leftTop + 480
Me.btnArchivedItems.Top = leftTop
'Reset the top location for the next column
leftTop = 496
'If the user is supposed to have the Add/Edit Folders button, show the button and place at leftTop
If DLookup("[AddEditFolderButton]", "[tblUsers]", "[UserID]='" & username & "'") = -1 Then
Me.btnAddEditFolders.Visible = True
'Set leftTop for next button in list
leftTop = leftTop + 480
Else
Me.btnAddEditFolders.Visible = False
End If
'Set the other buttons accordingly
Me.btnViewFolders.Top = leftTop
'Reset the top location for the next column
leftTop = 496
'Set the change password button to top of third column
Me.btnChangePass.Top = leftTop
leftTop = leftTop + 480
'If the user is supposed to have the Users button, show the button and place at leftTop
If DLookup("[AddEditUsers]", "[tblUsers]", "[UserID]='" & username & "'") = -1 Then
Me.btnUsers.Visible = True
Me.btnUsers.Top = leftTop
leftTop = leftTop + 480
Else
Me.btnUsers.Visible = False
End If
'If the user is supposed to have the Archive button, show the button and place at leftTop
If DLookup("[ArchiveButton]", "[tblUsers]", "[UserID]='" & username & "'") = -1 Then
Me.btnArchive.Visible = True
Me.btnArchive.Top = leftTop
leftTop = leftTop + 480
Else
Me.btnArchive.Visible = False
End If
DLookup:
Code:
'Set the form based on user rights and privileges
Dim username As String
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim leftTop As Integer
'This is the height on the form of the top buttons
leftTop = 496
'Lookup the current user logged in
username = DLookup("[LoggedIn]", "[tblCurrentUser]")
'Get the recordset of the username currently logged in
Set db = CurrentDb()
strSQL = "SELECT * FROM tblUsers WHERE ([UserID] = '" & username & "')"
Set rs = db.OpenRecordset(strSQL)
'If the user is supposed to have the Add/Edit Items button, show the button and place at leftTop
If rs("AddEditFileButton").Value = -1 Then
Me.btnAddEditItems.Visible = True
'Set leftTop for next button in list
leftTop = leftTop + 480
Else
Me.btnAddEditItems.Visible = False
End If
'Set the other buttons accordingly
Me.btnViewItems.Top = leftTop
leftTop = leftTop + 480
Me.btnOverdueItems.Top = leftTop
leftTop = leftTop + 480
Me.btnArchivedItems.Top = leftTop
'Reset the top location for the next column
leftTop = 496
'If the user is supposed to have the Add/Edit Folders button, show the button and place at leftTop
If rs("AddEditFolderButton").Value = -1 Then
Me.btnAddEditFolders.Visible = True
'Set leftTop for next button in list
leftTop = leftTop + 480
Else
Me.btnAddEditFolders.Visible = False
End If
'Set the other buttons accordingly
Me.btnViewFolders.Top = leftTop
'Reset the top location for the next column
leftTop = 496
'Set the change password button to top of third column
Me.btnChangePass.Top = leftTop
leftTop = leftTop + 480
'If the user is supposed to have the Users button, show the button and place at leftTop
If rs("AddEditUsers").Value = -1 Then
Me.btnUsers.Visible = True
Me.btnUsers.Top = leftTop
leftTop = leftTop + 480
Else
Me.btnUsers.Visible = False
End If
'If the user is supposed to have the Archive button, show the button and place at leftTop
If rs("ArchiveButton").Value = -1 Then
Me.btnArchive.Visible = True
Me.btnArchive.Top = leftTop
leftTop = leftTop + 480
Else
Me.btnArchive.Visible = False
End If
'Release recordset and database links
Set rs = Nothing
Set db = Nothing