Why code doesn't work on occation...

E

Eka1618

Hello,

I have been creating a database for the past 5 months and I have alot of VB
code going on throughout various forms and reports. The code that I have
works while I am testing it, but ocationally, certain lines of code or events
in general will not execute. Sometimes acesses totally freezes up. For
instance, if I try to send and e-mail, open a form, then close another form;
sometimes the e-mail wont send, or other times the form will not open.

In the end, My users will be using Access through all of the forms I have
created. I need the navigation to work no matter what... Has anyone ever
gotten into this situation? I just need to know what I can do to make my VB
code execute smoothly...

If anyone has any suggestions, please let me know, thank you!

~Erica~
 
G

Golfinray

Go into the code editor and go debug/compile. If your code has errors in it,
it won't compile. I will stop at every error until you fix the problem. If
you have already compiled, try decompiling and running compact and repair
then re-compile.
 
P

pietlinden

Also, add error trapping to each code event - at least then if your
code fails, you'll know where it's failing.
 
E

Eka1618

Well I compiled and it found one error. I couldn't find a decompile option
though, so I did a compact and repair, closed the file and re-opened it to
compile once more. I no longer have the option to compile the code anymore.
Does this mean that it is good? I'm going to be testing my forms out again,
but why couldn't you compile it again if you wanted to?

Also, I have some error handling, I'll work on creating more to see if
anything else comes up.

~Erica~
 
B

BruceM

Decompile is a command line option. For more information see:
http://www.granite.ab.ca/access/decompile.htm

Once code has compiled the option to compile it is not available. If you
edit a line of code (backspacing one character, then retyping it should be
enough) you will have the compile option available again, but if the code
has compiled then any problems with the code lie elsewhere, so there's not
much point to doing this.

For error handling there is a fine freeware utility that can insert error
handling at the click of a button, as well as performing a lot of other
tasks:
http://www.mztools.com/v3/mztools3.aspx
 
E

Eka1618

I have added some error handling at problem areas to see what happens, but I
am not getting messages I need to see...

For instance; The main form consist of links to other forms & reports. If a
user clicks on btnSingleKey (which opens frmOneKey), returns to the main form
after closing frmOneKey, then clicks btnSingleKey once again; when the form
opens/load it closes right away....

Here is the error check that I did:

Public Sub Form_Load()
On Error GoTo frmLoad_err

DoCmd.Maximize
Me.TYPE.SetFocus
Me.TYPE.Text = "Single Key"
Me.TITLE.SetFocus
Call SetDefaults(Me)

frmLoad_Exit:
Exit Sub

frmLoad_err:
MsgBox Error$
Resume frmLoad_Exit
End Sub
 
E

Eka1618

Hi Bruce,

I tried to decompile, but it is not working:

C:\Documents and Settings\EMM>C:\Program Files\Microsoft
Office\Office\MSACCESS.
EXE c:\My Documents\TestDatabase_6_5_08.mdb /decompile
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.


Here is what I typed in:
C:\Program Files\Microsoft Office\Office\MSACCESS.EXE c:\My
Documents\TestDatabase_6_5_08.mdb /decompile


I'm not sure what else to do...

~Erica~
 
E

Eka1618

Well I think that I am writing it wrong or something....

C:\Program" "Files\Microsoft" "Office\Office\MSACCESS.EXE c:\My"
"Documents\TestDatabase_6_5_08.mdb /decompile


I think my quotes are wrong...

~Erica~
 
E

Eka1618

Ok, THIS is the right path:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" /decompile
"c:\Documents and Settings\EMM\My Documents\TestDatabase_6_5_08.accdb"

I just cannot get anything to work....

~Erica~
 
B

BruceM

First of all, be sure Option Explicit appears at the top of each module,
just under Option Compare Database. If you need to add this manually to
each code module, change the option by going to Tools > Options in the VBA
editor. Click the Editor tab, and check the box for Require Variable
Declaration. Try to compile.

It looks like the right format for the decompile, but be sure that is the
actual path to Access.exe. Here is another link to well-explained and
thorough instructions:
http://allenbrowne.com/recover.html

However, I cannot say whether decompiling and all the rest will solve the
problem. If your code works sometimes and not at other times it is not
likely because of a compile error. It is more likely because the code does
not recognize a variable or field it is being called upon to use. With
error handling you can identify the event containing the troublesome code.
Once you know that you can set a break point in order to step through the
code one line at a time.
To set a break point, open the code editor. Click the vertical bar just to
the left of the code window. A red dot should appear, and the line of code
will be highlighted. Run the code by whatever means necessary (for
instance, if the code with the break point is in a command button Click
event, open the form and click the command button; if it is in a combo box
After Update event, make a selection from the combo box; etc.) The code
will pause at the break point. Press the F8 key to move to the next line of
code. Hover the mouse over field names and variables to be sure they are
what they should be. This technique, combined with error handling code,
should allow you to pinpoint errors. Once you know what they are you can
either solve the problem or post a specific question.
 
R

Rick A.B.

Ok, THIS is the right path:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" /decompile
"c:\Documents and Settings\EMM\My Documents\TestDatabase_6_5_08.accdb"

I just cannot get anything to work....

~Erica~
Erica,

Check you file path to access 2007 I would think your syntax should be
something like this.

"C:\Program Files\Microsoft Office\Office12\MSACCESS.EXE"
"c:\Documents and Settings\EMM\My Documents
\TestDatabase_6_5_08.accdb" /decompile
 
E

Eka1618

Thanks for the help here.

I was able to compile decompile it through Rick's example. and it works and
made the file MUCH smaller, but all of my problems still exist...

I've been stepping into the code to see what happens, and no errors occur. I
mean, I do not see anything in the immediate window. I am stepping through a
click and load event:

'*****************
' btnSingle_Click
'*****************
Private Sub btnSingle_Click()
On Error GoTo btnSingle_Click_Err
Me.Visible = False
DoCmd.OpenForm "frmOneKey", acNormal, "", "", , acNormal


btnSingle_Click_Exit:
Exit Sub

btnSingle_Click_Err:
MsgBox Error$
Resume btnSingle_Click_Exit

End Sub


'*****************
' Form_Load
'*****************
Public Sub Form_Load()
On Error GoTo frmLoad_err

DoCmd.Maximize
Me.TYPE.SetFocus
Me.TYPE.Text = "Single Key"
Me.TITLE.SetFocus
Call SetDefaults(Me)

frmLoad_Exit:
Exit Sub

frmLoad_err:
MsgBox Error$
Resume frmLoad_Exit
End Sub


In both examples, they end at the exit sub statement... is this correct? I
don't think so because the only way it would know to go there is from
entering the error, but I do not get any error messages or anything... in
fact it never steps through there, so I do not see how exit sub is being
executed.

Its so weird because you just cannot open them twice in a row, if i click on
a different form, then go back to the first form to reopen it it will be
fine. I dont understand how I can fix this...

~Erica~
 
B

BruceM

Comments and questions inline.

Eka1618 said:
Thanks for the help here.

I was able to compile decompile it through Rick's example. and it works
and
made the file MUCH smaller, but all of my problems still exist...

I've been stepping into the code to see what happens, and no errors occur.
I
mean, I do not see anything in the immediate window. I am stepping through
a
click and load event:

Where is the break point?
'*****************
' btnSingle_Click
'*****************
Private Sub btnSingle_Click()
On Error GoTo btnSingle_Click_Err
Me.Visible = False
DoCmd.OpenForm "frmOneKey", acNormal, "", "", , acNormal

This should be enough for the DoCmd line of code:
DoCmd.OpenForm "frmOneKey"
I have no idea what you hope to accomplish with the rest of the line
(although the first acNormal is OK, if unnecessary).
btnSingle_Click_Exit:
Exit Sub

btnSingle_Click_Err:
MsgBox Error$
Resume btnSingle_Click_Exit

End Sub


'*****************
' Form_Load
'*****************
Public Sub Form_Load()

Is this frmOneKey?
On Error GoTo frmLoad_err

DoCmd.Maximize
Me.TYPE.SetFocus
Me.TYPE.Text = "Single Key"

Why the text property? If you want the value of the Type field to be
"Single Key", just do:
Me.[TYPE] = "Single Key"

Note the bracket around Type. This is because Type is a reserved word in
Access. It should not be used as a name, but if it is it should be
surrounded with square brackets. For more about reserved words:
http://allenbrowne.com/AppIssueBadWord.html
Me.TITLE.SetFocus

What is SetDefaults? If it is a user-defined function or sub, you should be
going to that code when you reach the Call SetDefaults(Me) line of code.
Call SetDefaults(Me)

frmLoad_Exit:
Exit Sub

frmLoad_err:
MsgBox Error$
Resume frmLoad_Exit
End Sub


In both examples, they end at the exit sub statement... is this correct? I
don't think so because the only way it would know to go there is from
entering the error, but I do not get any error messages or anything... in
fact it never steps through there, so I do not see how exit sub is being
executed.

If there is an error the code will jump to frmLoad_err. If there is no
error, the code will end up eventually at Exit Sub because it is the next
line of code. The frmLoad_err will send the code to Exit Sub also, but
again, at some point it is just the next line of code if there is no error.
Its so weird because you just cannot open them twice in a row, if i click
on
a different form, then go back to the first form to reopen it it will be
fine. I dont understand how I can fix this...

Cannot open what twice in a row? What do you mean by "go back to the first
form to reopen it"? In what way is it "fine" the second time that it is not
the first time?
 
E

Eka1618

Bruce,

thanks for some of these tips. I am still trying to work on cleaning up my
code. However, I did finally figure out what the problem was with the forms
closing on me. In a module where I call the SetDefaults() function, I was
saying:

docmd.close acform frmMain...

That was BAD! LOL, well I didn't realize it was in there at the time anyway.
I am going to work on changing the 'TYPE' name I've called my one field. I
didnt know it was reserved. And as for the .text stuff; I do that all the
time. I learned visual basic in a VB course I took last semester and my
teacher taught us to do it this way. I didn't learn VB in Access and I've had
to teach myself how to code in it. Many aspects are alike so I have been able
to adapt with what I know from that course.

I am an intern where I work and so I do not have much help with this DB so
these forums and a couple books is all I've got as resources.

Thank you for the help, I may have more questions soon :)

~Erica~

BruceM said:
Comments and questions inline.

Eka1618 said:
Thanks for the help here.

I was able to compile decompile it through Rick's example. and it works
and
made the file MUCH smaller, but all of my problems still exist...

I've been stepping into the code to see what happens, and no errors occur.
I
mean, I do not see anything in the immediate window. I am stepping through
a
click and load event:

Where is the break point?
'*****************
' btnSingle_Click
'*****************
Private Sub btnSingle_Click()
On Error GoTo btnSingle_Click_Err
Me.Visible = False
DoCmd.OpenForm "frmOneKey", acNormal, "", "", , acNormal

This should be enough for the DoCmd line of code:
DoCmd.OpenForm "frmOneKey"
I have no idea what you hope to accomplish with the rest of the line
(although the first acNormal is OK, if unnecessary).
btnSingle_Click_Exit:
Exit Sub

btnSingle_Click_Err:
MsgBox Error$
Resume btnSingle_Click_Exit

End Sub


'*****************
' Form_Load
'*****************
Public Sub Form_Load()

Is this frmOneKey?
On Error GoTo frmLoad_err

DoCmd.Maximize
Me.TYPE.SetFocus
Me.TYPE.Text = "Single Key"

Why the text property? If you want the value of the Type field to be
"Single Key", just do:
Me.[TYPE] = "Single Key"

Note the bracket around Type. This is because Type is a reserved word in
Access. It should not be used as a name, but if it is it should be
surrounded with square brackets. For more about reserved words:
http://allenbrowne.com/AppIssueBadWord.html
Me.TITLE.SetFocus

What is SetDefaults? If it is a user-defined function or sub, you should be
going to that code when you reach the Call SetDefaults(Me) line of code.
Call SetDefaults(Me)

frmLoad_Exit:
Exit Sub

frmLoad_err:
MsgBox Error$
Resume frmLoad_Exit
End Sub


In both examples, they end at the exit sub statement... is this correct? I
don't think so because the only way it would know to go there is from
entering the error, but I do not get any error messages or anything... in
fact it never steps through there, so I do not see how exit sub is being
executed.

If there is an error the code will jump to frmLoad_err. If there is no
error, the code will end up eventually at Exit Sub because it is the next
line of code. The frmLoad_err will send the code to Exit Sub also, but
again, at some point it is just the next line of code if there is no error.
Its so weird because you just cannot open them twice in a row, if i click
on
a different form, then go back to the first form to reopen it it will be
fine. I dont understand how I can fix this...

Cannot open what twice in a row? What do you mean by "go back to the first
form to reopen it"? In what way is it "fine" the second time that it is not
the first time?
 
B

BruceM

Good luck with using the text property. I doubt it will give you what you
expect in many cases.

Eka1618 said:
Bruce,

thanks for some of these tips. I am still trying to work on cleaning up my
code. However, I did finally figure out what the problem was with the
forms
closing on me. In a module where I call the SetDefaults() function, I was
saying:

docmd.close acform frmMain...

That was BAD! LOL, well I didn't realize it was in there at the time
anyway.
I am going to work on changing the 'TYPE' name I've called my one field. I
didnt know it was reserved. And as for the .text stuff; I do that all the
time. I learned visual basic in a VB course I took last semester and my
teacher taught us to do it this way. I didn't learn VB in Access and I've
had
to teach myself how to code in it. Many aspects are alike so I have been
able
to adapt with what I know from that course.

I am an intern where I work and so I do not have much help with this DB so
these forums and a couple books is all I've got as resources.

Thank you for the help, I may have more questions soon :)

~Erica~

BruceM said:
Comments and questions inline.

Eka1618 said:
Thanks for the help here.

I was able to compile decompile it through Rick's example. and it works
and
made the file MUCH smaller, but all of my problems still exist...

I've been stepping into the code to see what happens, and no errors
occur.
I
mean, I do not see anything in the immediate window. I am stepping
through
a
click and load event:

Where is the break point?
'*****************
' btnSingle_Click
'*****************
Private Sub btnSingle_Click()
On Error GoTo btnSingle_Click_Err
Me.Visible = False
DoCmd.OpenForm "frmOneKey", acNormal, "", "", , acNormal

This should be enough for the DoCmd line of code:
DoCmd.OpenForm "frmOneKey"
I have no idea what you hope to accomplish with the rest of the line
(although the first acNormal is OK, if unnecessary).
btnSingle_Click_Exit:
Exit Sub

btnSingle_Click_Err:
MsgBox Error$
Resume btnSingle_Click_Exit

End Sub


'*****************
' Form_Load
'*****************
Public Sub Form_Load()

Is this frmOneKey?
On Error GoTo frmLoad_err

DoCmd.Maximize
Me.TYPE.SetFocus
Me.TYPE.Text = "Single Key"

Why the text property? If you want the value of the Type field to be
"Single Key", just do:
Me.[TYPE] = "Single Key"

Note the bracket around Type. This is because Type is a reserved word in
Access. It should not be used as a name, but if it is it should be
surrounded with square brackets. For more about reserved words:
http://allenbrowne.com/AppIssueBadWord.html
Me.TITLE.SetFocus

What is SetDefaults? If it is a user-defined function or sub, you should
be
going to that code when you reach the Call SetDefaults(Me) line of code.
Call SetDefaults(Me)

frmLoad_Exit:
Exit Sub

frmLoad_err:
MsgBox Error$
Resume frmLoad_Exit
End Sub


In both examples, they end at the exit sub statement... is this
correct? I
don't think so because the only way it would know to go there is from
entering the error, but I do not get any error messages or anything...
in
fact it never steps through there, so I do not see how exit sub is
being
executed.

If there is an error the code will jump to frmLoad_err. If there is no
error, the code will end up eventually at Exit Sub because it is the next
line of code. The frmLoad_err will send the code to Exit Sub also, but
again, at some point it is just the next line of code if there is no
error.
Its so weird because you just cannot open them twice in a row, if i
click
on
a different form, then go back to the first form to reopen it it will
be
fine. I dont understand how I can fix this...

Cannot open what twice in a row? What do you mean by "go back to the
first
form to reopen it"? In what way is it "fine" the second time that it is
not
the first time?
~Erica~


:

First of all, be sure Option Explicit appears at the top of each
module,
just under Option Compare Database. If you need to add this manually
to
each code module, change the option by going to Tools > Options in the
VBA
editor. Click the Editor tab, and check the box for Require Variable
Declaration. Try to compile.

It looks like the right format for the decompile, but be sure that is
the
actual path to Access.exe. Here is another link to well-explained and
thorough instructions:
http://allenbrowne.com/recover.html

However, I cannot say whether decompiling and all the rest will solve
the
problem. If your code works sometimes and not at other times it is
not
likely because of a compile error. It is more likely because the code
does
not recognize a variable or field it is being called upon to use.
With
error handling you can identify the event containing the troublesome
code.
Once you know that you can set a break point in order to step through
the
code one line at a time.
To set a break point, open the code editor. Click the vertical bar
just
to
the left of the code window. A red dot should appear, and the line of
code
will be highlighted. Run the code by whatever means necessary (for
instance, if the code with the break point is in a command button
Click
event, open the form and click the command button; if it is in a combo
box
After Update event, make a selection from the combo box; etc.) The
code
will pause at the break point. Press the F8 key to move to the next
line
of
code. Hover the mouse over field names and variables to be sure they
are
what they should be. This technique, combined with error handling
code,
should allow you to pinpoint errors. Once you know what they are you
can
either solve the problem or post a specific question.

Ok, THIS is the right path:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" /decompile
"c:\Documents and Settings\EMM\My
Documents\TestDatabase_6_5_08.accdb"

I just cannot get anything to work....

~Erica~

:

Decompile is a command line option. For more information see:
http://www.granite.ab.ca/access/decompile.htm

Once code has compiled the option to compile it is not available.
If
you
edit a line of code (backspacing one character, then retyping it
should
be
enough) you will have the compile option available again, but if
the
code
has compiled then any problems with the code lie elsewhere, so
there's
not
much point to doing this.

For error handling there is a fine freeware utility that can insert
error
handling at the click of a button, as well as performing a lot of
other
tasks:
http://www.mztools.com/v3/mztools3.aspx

Well I compiled and it found one error. I couldn't find a
decompile
option
though, so I did a compact and repair, closed the file and
re-opened
it
to
compile once more. I no longer have the option to compile the
code
anymore.
Does this mean that it is good? I'm going to be testing my forms
out
again,
but why couldn't you compile it again if you wanted to?

Also, I have some error handling, I'll work on creating more to
see
if
anything else comes up.

~Erica~

:

Go into the code editor and go debug/compile. If your code has
errors
in
it,
it won't compile. I will stop at every error until you fix the
problem.
If
you have already compiled, try decompiling and running compact
and
repair
then re-compile.

:

Hello,

I have been creating a database for the past 5 months and I
have
alot
of VB
code going on throughout various forms and reports. The code
that
I
have
works while I am testing it, but ocationally, certain lines of
code
or
events
in general will not execute. Sometimes acesses totally freezes
up.
For
instance, if I try to send and e-mail, open a form, then
close
another
form;
sometimes the e-mail wont send, or other times the form will
not
open.

In the end, My users will be using Access through all of the
forms I
have
created. I need the navigation to work no matter what... Has
anyone
ever
gotten into this situation? I just need to know what I can do
to
make
my VB
code execute smoothly...

If anyone has any suggestions, please let me know, thank you!

~Erica~
 
Top