Hi,
Do I need to close a recordset on form_load() if it is a dbOpenSnapshot?
Thanks
Ah. With that code displayed it now becomes clear what your question should have included!
Here are some tips : - When using Recordsets in VBA it's important to specify which type of Recordset you mean as both DAO & ADODB have Recordset objects and if you don't specify then your code is ambiguous depending on which library is first in the list. So,
Dim rs As DAO.Recordset - It's actually not critical that you close the Recordset at the end of the procedure as you close the form that it's declared within anyway. Thus it goes out of scope and is tidied away automatically for you. That said, it's certainly good practice to close and tidy any objects created within your code.
- The fact that the Recordset is a spnapshot doesn't really come into it.
Hopefully these tips will answer all your questions.
6 1867
Seeing your code would be helpful in answering this question.
Generally speaking, it's best to explicitly close a RecordSet when you are finished with it. The only time I can think of that you wouldn't would be when opening a RecordSet through code and then setting the Form's RecordSet to that of the opened RecordSet. I don't normally set a Form's RecordSet in this manner, so I'm just going from memory of what I've seen others do.
this is the code, still working on it though. I never used snapshot before but reading about it I thought in this case it might fit ok. - Private Sub cmdLogin_Click()
-
On Error GoTo ErrorHandler
-
-
Dim db As Database
-
Dim rs As Recordset
-
Dim cmdCategory As CommandButton
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset("tblEmployees", dbOpenSnapshot, dbReadOnly)
-
-
'loop through recorset and find value
-
rs.FindFirst "EmployeeName='" & Me.txtUserName & "'"
-
-
'check username
-
If rs.NoMatch = True Then
-
Me.lblWrongUser.Visible = True
-
Me.txtUserName.SetFocus
-
Exit Sub
-
End If
-
Me.lblWrongUser.Visible = False
-
-
'check password
-
If rs!Password <> Nz(Me.txtPassword, "") Then
-
Me.lblWrongPassword.Visible = True
-
Me.txtPassword.SetFocus
-
Exit Sub
-
End If
-
Me.lblPassword.Visible = False
-
-
DoCmd.OpenForm "frmMain"
-
DoCmd.Close acForm, Me.Name
-
-
'close recordset
-
rs.Close
-
-
ExitSub:
-
Set rs = Nothing
-
Set db = Nothing
-
Exit Sub
-
ErrorHandler:
-
MsgBox "Error No: " & Err.Number & vbNewLine _
-
& "Error Details: " & Err.Description & vbNewLine _
-
& "Calling Sub: frmLogin\cmdLogin_Click()"
-
Resume ExitSub
-
End Sub
NeoPa 32,556
Expert Mod 16PB
This is a bit of a strange question. If the recordset you're talking about is form's recordset then you neither need to, nor can, close it without closing the form.
NeoPa 32,556
Expert Mod 16PB
Ah. With that code displayed it now becomes clear what your question should have included!
Here are some tips : - When using Recordsets in VBA it's important to specify which type of Recordset you mean as both DAO & ADODB have Recordset objects and if you don't specify then your code is ambiguous depending on which library is first in the list. So,
Dim rs As DAO.Recordset - It's actually not critical that you close the Recordset at the end of the procedure as you close the form that it's declared within anyway. Thus it goes out of scope and is tidied away automatically for you. That said, it's certainly good practice to close and tidy any objects created within your code.
- The fact that the Recordset is a spnapshot doesn't really come into it.
Hopefully these tips will answer all your questions.
I'll include the code next time, you are right. Will use tag too.
1) Got it wrong in 2 procedures. Dao is first in library.
2) Got it
3) Got it
Excellent! they certainly answer them, Thanks
NeoPa 32,556
Expert Mod 16PB
I'm always pleased to help Neruda, but especially when someone is so ready to learn and progress. Good for you :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dmiller23462 |
last post by:
My brain is nuked....Can anybody tell me right off the bat what is
wrong with this code? Along with any glaring errors, please let me
know the syntax to display a message (Response.Write would be...
|
by: bluedolphin |
last post by:
Hello All:
I have been brought onboard to help on a project that had some
performance problems last year. I have taken some steps to address
the issues in question, but a huge question mark...
|
by: James Birkholz via AccessMonster.com |
last post by:
A few months ago, a working Access97 system started exhibiting this behavior. About half the time when the .mde is closed, the app window remains open and can then only be closed by using "End task"...
|
by: Lauren Quantrell |
last post by:
Does changing the Recordset Type property for a form in an Access ADP
have any effect on possible record locking?
I have a continuous form that is bound to a table but I don't want it
editable,...
|
by: BillCo |
last post by:
This worked for a large database (150+ tables):
Do While Not rstLinks.EOF
Set td = DB.TableDefs(rstLinks!Name)
'Debug.Print rstLinks!Name
If InStr(td.Connect, "corpbe.mdb") Then
td.Connect =...
|
by: ruthboaz |
last post by:
Hi,
I am upgrading the current ms access .mdb file to a .adp with sql server back end.
I have been converted tables, forms, reports to .adp..
The tables are reflected at the server.
a)
...
|
by: =?Utf-8?B?R3JlZw==?= |
last post by:
My background is in MS Access and I am in the process of migrating my
skillsets to Visual Basic.Net. So far I am able to display data in
DataGridViews and Combo Box, etc with not problem. What I'm...
|
by: lee weaver |
last post by:
I have a form to edit employee data that is a copy of the add employee form ( Which works great) with a list box at the top to select the employee to edit that is susposed to navigate to the correct...
|
by: Seth Schrock |
last post by:
I know that I can do this using a temp table, but I'm hoping for another solution that would be easier. I want to be able to open a form (in continuous view) with the current data and play with the...
|
by: dgunner71 |
last post by:
All,
As I'm working through an odd locking issue (separate post), I'm wondering if it is best (or at all beneficial) to employ snapshot RecordSet types (on forms) - specifically where I would...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |