MS Access 2K command button code problem 
Author Message
 MS Access 2K command button code problem

I am currently building a solution to a "ScanTron" type document.  The
problem that i am having is as follows:

Project:

The project consists of one main data entry table and several forms.  I am
having to use several forms to free up ram on some of my slower computers.
The main components of the project are named as follows:

Main table = PCR
Form 1 = Vehicle and Time Information
Form 2 = Response Information

Problems:

I am trying to use one button to save data to the table, close the first
form and open the second.  I initially put 3 buttons on the form and then
extracted the code and compiled it on to one button to make it easier for
the user.  The code is as follows:

Private Sub Command48_Click()
On Error GoTo Err_Command48_Click

    DoCmd.GoToRecord , , acNewRec
    stDocName = "Response Information"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close

Exit_Command48_Click:
    Exit Sub

Err_Command48_Click:
    MsgBox Err.Description
    Resume Exit_Command48_Click

End Sub

When using this code, the record is made as directed but the second form
(Response Informations) flashes on screen and the first form (called Vehicle
and Time Information) is returned to the screen.
If i delete the "DoCmd.Close" line, the record is made, the second form is
properly displayed but the first form stays loaded leaving unnecessary
memory occupation.

Questions:

1.  Is there code for MS Access that would "hide" and "unload" the first
form that i could insert instead of or in addition to the above stated code?
2.  Is the [stDocName = "Response Information"] section of the code making
an easy referral for the first form for recognition in the line
[DoCmd.OpenForm stDocName, , , stLinkCriteria]  and if so, would it be
appropriate to make such a line for the Close command to specify a specific
object type and name to close the first form.
3.  Is closing the form the same as unloading it from memory, or is there a
seperate command.

This application will later be written in VB once i get a good grip on MS
Access data storage.  I do not have SQL available, nor to i have the
knowledge (yet) for using SQL.  I am a beginner developer having to work at
home to teach myself this.

Thank you for any information that you can give

John C. Duchock



Tue, 19 Mar 2002 03:00:00 GMT  
 MS Access 2K command button code problem

Quote:

> <snip>
> I am trying to use one button to save data to the table, close the first
> form and open the second.  I initially put 3 buttons on the form and then
> extracted the code and compiled it on to one button to make it easier for
> the user.  The code is as follows:
> <snip - see original post>
> When using this code, the record is made as directed but the second form
> (Response Informations) flashes on screen and the first form (called Vehicle
> and Time Information) is returned to the screen.
> If i delete the "DoCmd.Close" line, the record is made, the second form is
> properly displayed but the first form stays loaded leaving unnecessary
> memory occupation.

> Questions:

> 1.  Is there code for MS Access that would "hide" and "unload" the first
> form that i could insert instead of or in addition to the above stated code?
> 2.  Is the [stDocName = "Response Information"] section of the code making
> an easy referral for the first form for recognition in the line
> [DoCmd.OpenForm stDocName, , , stLinkCriteria]  and if so, would it be
> appropriate to make such a line for the Close command to specify a specific
> object type and name to close the first form.
> 3.  Is closing the form the same as unloading it from memory, or is there a
> seperate command.

> This application will later be written in VB once i get a good grip on MS
> Access data storage.  I do not have SQL available, nor to i have the
> knowledge (yet) for using SQL.  I am a beginner developer having to work at
> home to teach myself this.

John,
  You posted this to 2 VB newsgroups - you may want to look for an
actual Access group (VBA) for more help.  I started out programming in
Access VBA before switching to "real" VB, so I'll take a stab at working
on this with ya.
   Looks to me like this is what's happening in your code:

    stDocName = "Response Information"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
        [okay, "Response Info"  is now open, so it is the active object]
    DoCmd.Close
        ["Close" acts on the active object, which is the "Response
          Info" form - so you opened it then closed it immediately,
          which explains why it just "flashes on the screen"]

As you suspect, you need to revise your Close statement to specify
*what* you intend to close.  I have Access97, so check that this syntax
is still correct by looking up "Close method" in your Access2K Help:

DoCmd.Close acForm, "Vehicle and Time Information"

AFAIK, "Close" in Access unloads the form and all its controls from RAM.
  A couple other points (not criticizing, just encouraging you to
develop good habits as you learn to code):  it's helpful to name your
objects so their use is more apparent - instead of "Command48", name
this button something like "cmdSave_ShowRespInfo".  When you look at
this code 6 months from now, that can help you remember exactly what
each button does.  
  Using spaces in object names (like your form names) can lead to
unexpected hassles later.  A common practice is to name the form
"frmResponseInfo" and set the form's caption to the more user-freindly
"Response Information."
  You *can* use SQL statements in Access and in VB, so not sure what you
mean by not having SQL available - I realize that's more to learn.
  It's gonna be a learning curve when you switch to VB, since in VB we
don't have the DoCmd object, or LoadForm and Close methods.  There's a
whole new set of method names and syntax you'll need to learn.  If
you're going to write this in VB, I'd say go for it right now.  Get a
good beginner's book like Peter Wright's "Beginning Visual Basic 6"
(Wrox Press) or the Sams Publishing "Teach Yourself Database Programming
with Visual Basic 6 in 21 Days".  Unfortunatly, VB books currently on
the market predate Access2k, so you'll need to check Microsoft web site
for latest info about the correct DAO or Jet references to update what's
in the books if you want Access2k db's - the books all assume Access97.
And post your questions on this n.g.
  Have fun with it!
--
Jim in Cleveland
If you're writing to me, in my address
change "REAL_Address.see.below" to "worldnet.att.net"

"What's so funny 'bout peace, love & understanding?"
     - Nick Lowe



Tue, 19 Mar 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Command button won't make use of module driving MS Project from MS Access 2000

2. Problems with Access/Outlook 2K VBA when run using NT's AT command

3. Command Button Color (MS-ACCESS)

4. MS Access Build Code button

5. MS Access Build Code button

6. call command button click command from code

7. Problem with command buttons in Access 7

8. MS Access 97 Print button problem

9. Hover Button style command buttons in Access 97?

10. HowTo: Reuse ADO Command Params w/ Access 2K DB

11. Access 2K with Win 2K

12. Save and close excel 2k from access 2k

 

 
Powered by phpBB® Forum Software