
Newbie Application.Quit Question
Thanks for taking the time to post a response to me on
microsoft.public.access.modulesdaovba. I didn't know that you could use the
current access connection with the CurrentProject.Connection property. I
will rewrite the form module tomorrow and see how it goes.
Thanks,
Collin Smith
Quote:
> <<
> <<Hi,
> <<
> << Essentially I'm trying to write a little pop up form in access
everytime
> <<I turn on my computer to let me know if someone has a birthday within 15
> <<days or not. My first form automatically starts when the database is
> <<opened. It is called frmOpener. Here is the code for frmOpener.
> <<Essentially what the form does is pull a record set. If the recordset
is
> <<not null the form opens another form which has a list of all the people
with
> <<upcoming birthdays within 15 days. If the recordset is null then Access
> <<quits by using the Application.Quit command. The problem is that after
> <<Access quits a dialog box pops up saying "Cannot find file....mydb
etc...".
> <<It seems like Access is closing so fast that it still wants to do
something
> <<but then since it did close it can't find what it needs. Any
suggestions?
> <<
> <<Thank you,
> <<
> <<CS
> <<
> <<
> Hello,
> There are couple of things you should change in the code. First, check the
RecordCount property of the recordset
Quote:
> to determine if it contains records or not, instead of checking to see if
it is null. The variable should never
Quote:
> be null even when the recordset contains no records. Second, the code is
opening a separate ADO connection to
Quote:
> the database when you should just share the one that Access is using,
which is exposed by the
Quote:
> CurrentProject.Connection property. Here is the modified code which is
working for me.
> Private Sub Form_Load()
> Dim oConn As ADODB.Connection
> Dim rs As ADODB.Recordset
> Set oConn = CurrentProject.Connection
> Set rs = New ADODB.Recordset
> Dim msg As String
> msg = "SELECT * FROM qryBirthDaysComing"
> rs.Open msg, oConn, adOpenKeyset, adLockOptimistic
> If rs.RecordCount > 0 Then
> MsgBox "You have Birthdays within 15 days."
> DoCmd.OpenForm ("frmBirthDays")
> Else
> Application.Quit
> End If
> rs.Close
> Set rs = Nothing
> Set oConn = Nothing
> DoCmd.Close acForm, Me.Name
> End Sub
> I hope this helps!
> Sincerely,
> Keith Fink
> Microsoft Developer Support