473,382 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Access closes when activating vba code

I have a weird problem that I'm trying to solve but can't seem to find
a solution at this time. My Access database closes completely when the
"Else" of the VBA code is applicable.

I'm running Access XP Pro (2002) french on WinXP
Form: frm_commande (data coming from Qry_Commande)
Subform: sfrm_commande_detail

The following VBA code is running on Form_Current event of the subform.
All the fields used in the code are in the footer of the subform and I
created a two dummy text fields to help get the data. These data are
not saved in any tables, they are just used to calculate information.

Dummy 1 - Date_Facture which equals the Date_facturation field of the
form (I tried using the field of the form directly but I get the same
result).

Dummy 2 - TauxTPS which is used to get the dynamic rate that will be
used to calculate the proper tax amount according to the date.

Me.Refresh
If (IsNull(Me.Date_Facture)) Or Me.Date_Facture = " " Then
Exit Sub
Else
Me.Refresh
If Me.Date_Facture < Me.Date_juillet Then
Me.TauxTPS.ControlSource = "=0.07"
Else
Me.TauxTPS.ControlSource = "=0.06"
End If
End If

As soon as I have data in the Date_Facture field which is a core data
to establish the rate, the Access database closes completely... no
error message nothing. Tried to compact and repair the DB... still no
success. Anybody has an idea???

Jun 29 '06 #1
2 2571
Let's do some basic repair:

1. Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Explanation of why:
http://allenbrowne.com/bug-03.html

2. Compact the database to get rid of this junk:
Tools | Database Utilities | Compact

3. Close Access. Make a backup copy of the file. Decompile the database by
entering something like this at the command prompt while Access is not
running. It is all one line, and include the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

4. Open Access, and compact again.

With that done, let's try some specifics on this routine:

1. Remove the lines:
Me.Refresh
The record canot be dirty in this event.

2. Leave TAUTPS unbound (nothing in its ControlSource.)
Set is Format property to:
General Number
so Access knows it is a numeric value.

3. Try this in the Current event procedure of the form
Private Sub Form_Current()
Dim dblTausTPS
If Me.Date_facturation < Me.Date_juillet Then
Me.TauxTPS = 0.07
ElseIf Not IsNull(Me.Date_facturation) Then
Me.TauxTPS = 0.06
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Beejer" <bj********@yahoo.ca> wrote in message
news:11**********************@d56g2000cwd.googlegr oups.com...
I have a weird problem that I'm trying to solve but can't seem to find
a solution at this time. My Access database closes completely when the
"Else" of the VBA code is applicable.

I'm running Access XP Pro (2002) french on WinXP
Form: frm_commande (data coming from Qry_Commande)
Subform: sfrm_commande_detail

The following VBA code is running on Form_Current event of the subform.
All the fields used in the code are in the footer of the subform and I
created a two dummy text fields to help get the data. These data are
not saved in any tables, they are just used to calculate information.

Dummy 1 - Date_Facture which equals the Date_facturation field of the
form (I tried using the field of the form directly but I get the same
result).

Dummy 2 - TauxTPS which is used to get the dynamic rate that will be
used to calculate the proper tax amount according to the date.

Me.Refresh
If (IsNull(Me.Date_Facture)) Or Me.Date_Facture = " " Then
Exit Sub
Else
Me.Refresh
If Me.Date_Facture < Me.Date_juillet Then
Me.TauxTPS.ControlSource = "=0.07"
Else
Me.TauxTPS.ControlSource = "=0.06"
End If
End If

As soon as I have data in the Date_Facture field which is a core data
to establish the rate, the Access database closes completely... no
error message nothing. Tried to compact and repair the DB... still no
success. Anybody has an idea???

Jun 30 '06 #2
Allen, your my savior!!!

It is working like a charm. Thank you so much.

Bruno

Allen Browne a écrit :
Let's do some basic repair:

1. Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Explanation of why:
http://allenbrowne.com/bug-03.html

2. Compact the database to get rid of this junk:
Tools | Database Utilities | Compact

3. Close Access. Make a backup copy of the file. Decompile the database by
entering something like this at the command prompt while Access is not
running. It is all one line, and include the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

4. Open Access, and compact again.

With that done, let's try some specifics on this routine:

1. Remove the lines:
Me.Refresh
The record canot be dirty in this event.

2. Leave TAUTPS unbound (nothing in its ControlSource.)
Set is Format property to:
General Number
so Access knows it is a numeric value.

3. Try this in the Current event procedure of the form
Private Sub Form_Current()
Dim dblTausTPS
If Me.Date_facturation < Me.Date_juillet Then
Me.TauxTPS = 0.07
ElseIf Not IsNull(Me.Date_facturation) Then
Me.TauxTPS = 0.06
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Beejer" <bj********@yahoo.cawrote in message
news:11**********************@d56g2000cwd.googlegr oups.com...
I have a weird problem that I'm trying to solve but can't seem to find
a solution at this time. My Access database closes completely when the
"Else" of the VBA code is applicable.

I'm running Access XP Pro (2002) french on WinXP
Form: frm_commande (data coming from Qry_Commande)
Subform: sfrm_commande_detail

The following VBA code is running on Form_Current event of the subform.
All the fields used in the code are in the footer of the subform and I
created a two dummy text fields to help get the data. These data are
not saved in any tables, they are just used to calculate information.

Dummy 1 - Date_Facture which equals the Date_facturation field of the
form (I tried using the field of the form directly but I get the same
result).

Dummy 2 - TauxTPS which is used to get the dynamic rate that will be
used to calculate the proper tax amount according to the date.

Me.Refresh
If (IsNull(Me.Date_Facture)) Or Me.Date_Facture = " " Then
Exit Sub
Else
Me.Refresh
If Me.Date_Facture < Me.Date_juillet Then
Me.TauxTPS.ControlSource = "=0.07"
Else
Me.TauxTPS.ControlSource = "=0.06"
End If
End If

As soon as I have data in the Date_Facture field which is a core data
to establish the rate, the Access database closes completely... no
error message nothing. Tried to compact and repair the DB... still no
success. Anybody has an idea???
Jul 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Denis | last post by:
I am trying to launch an .mdb file via javascript. I do not need to do anything but open the application. It is able to open the application but for some reason it opens and then closes. At...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
1
by: Nathan Bloom | last post by:
Is there a way to force the user of a database to exit and close access through a close button on for example a switchboard menu? If a user closes access by the exit command or the close button...
7
by: Colleyville Alan | last post by:
I have an app that uses Access to grab various PowerPoint slides using the followhyperlink command. I have set the PPT window to run in a minimized state: FollowHyperlink link Set oPres =...
0
by: dlieu | last post by:
I've found an odd situation in where the Load event of the active form fires (after the Unload event) when Access is closed. I am able to reproduce this situation in Access 2002 SP3 and Access 2003...
0
by: x taol | last post by:
access application are 2. coding below code in one application..... VBA.AppActivate "the other access title" this code does not work when the access application is minimized. though, i want...
1
by: DelScorcho | last post by:
Hi, I'm using a VB6 application to open MS Access; and it works fine, but when the code completes execution, Access automatically closes (I want it to stay open).... I've written code like this...
4
by: Chris | last post by:
I reference a DLL that was developed in VB 6.0 in MSAccess program & Excel add-in. When I close my Excel add-in, Excel closes without any problem. When I close my Access program, Access does not...
0
by: Mark Gold | last post by:
Hi! We have a VB application using Crystal Reports 6 that has worked successfully on hundreds of systems for over 10 years. Now, on one network, the application and access database does not close....
1
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.