Newbie Application.Quit Question 
Author Message
 Newbie Application.Quit Question

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

Private Sub Form_Load()

    Dim oConn As New ADODB.Connection
    Dim myDB
    Set myDB = CurrentDb
    oConn.Provider = "Microsoft.Jet.OLEDB.4.0"
    oConn.ConnectionString = "data source = " & myDB.Name
    oConn.Open

    Dim rs
    Set rs = New ADODB.Recordset
    Dim msg As String
    msg = "Select * from qryBirthDaysComing "
    rs.Open msg, oConn, 1, 3

    If not IsNull(rs) Then
        MsgBox "You have Birthdays within 15 days."
        DoCmd.OpenForm ("frmBirthDays")
    Else
        Application.Quit
    End If

    rs.Close
    Set rs = Nothing
    oConn.Close
    Set oConn = Nothing
    DoCmd.Close acForm, "frmOpener"

End Sub



Fri, 26 Dec 2003 11:00:16 GMT  
 Newbie Application.Quit Question

<<
<<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
to determine if it contains records or not, instead of checking to see if it is null. The variable should never
be null even when the recordset contains no records. Second, the code is opening a separate ADO connection to
the database when you should just share the one that Access is using, which is exposed by the
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



Fri, 26 Dec 2003 22:27:09 GMT  
 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

- Show quoted text -

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



Sun, 28 Dec 2003 14:02:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Newbie Application.Quit Question

2. Newbie question: access 97 ONLY from VB application

3. Newbie Simple Question: How to place icon on desktop during setup of created application

4. Newbie Question-Application Wizard - How to!

5. newbie question - trying to start applications with .vbs file

6. Newbie Question - IIS application

7. VB Applications and Access (Newbie question)

8. Newbie Question---Database structure for custom accounting application

9. Newbie Question - porting an access application

10. Newbie question:- Application.System.PrivateProfileString.

11. Newbie Question - Packaging Applications From 32 Bit Systems to 16 Bit Systems

12. Another Newbie Question: Searching the VB application

 

 
Powered by phpBB® Forum Software