473,387 Members | 3,810 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,387 software developers and data experts.

VBA Experssion Error with linked table

255 100+
Hi guys,

I just takeover to continue on a database project with a bug, the code seems all good, but it didn't pass through an execute SQL statement. Here the part of code that stucked:
Expand|Select|Wrap|Line Numbers
  1.         If main.UserAction = main.UserSelected Then
  2.  
  3.             myDb.Execute "INSERT INTO ArchiveEmployees SELECT * FROM Employees WHERE ID=" & [txtID]                    
  4.  
  5.             If myDb.RecordsAffected = 1 Then
  6.  
  7.                 DeactiveDate = main.g_FmtDate
  8.                 Comment = main.g_Str
  9.  
  10.                 myDb.Execute " UPDATE ArchiveEmployees SET [Date Terminated] = " & DeactiveDate & ", " & _
  11.                 "  Comments ='" & Comment & "'" & _
  12.                 " WHERE ID = " & [txtID]
  13.  
  14.                 myDb.Execute " Delete * FROM Employees WHERE ID=" & [txtID]
  15.  
  16.                 MsgBox " Archive Success !", vbInformation + vbOKOnly, " Operation complete"
  17.             Else
  18.                 MsgBox " Cannot copy records to the Archive Table", _
  19.                     vbOKOnly + vbCritical, " Operation Failed"
  20.             End If
  21.  
  22.             Me.Requery
  23.             Me.Refresh
  24. End If
The expression is trying to move any leaving staff from one table to another, both tables are linked from another access mdb. The line in bold is where the process stops, but this whole expression in previous versions did work where its exactly the same. I had suspected that its because the code was supported in Access 97 but not in Access 2003, but as the file format is compatable to both version I don't think such fact matters. So how can I fix this error? Thanks.

Colin
Mar 26 '10 #1

✓ answered by NeoPa

@colintis
Generally, when the compile option is greyed out it means the code is already successfully compiled. This is a good status.

Otherwise, the error message seems to be pointing towards an issue with the configuration of the form - in that it doesn't like the procedure you linked to to handle the event. This may be due to security settings on an MDE. I'm not really sure.

When the code runs and stops on the myDB.Execute line, there should be an error message displayed there too. We're a bit stuck without that info to be fair. There is nothing obviously wrong I can see, but then I don't know your database. It could be something that cannot work within your database specifically.

7 2621
NeoPa
32,556 Expert Mod 16PB
A good start would be to report the error message that you get when you attempt to run this code.

I'm assuming the variable MyDB is already set up correctly, as this code isn't included, but maybe it would be a good idea to post that as well.
Mar 26 '10 #2
NeoPa
32,556 Expert Mod 16PB
Actually, check these out before posting too. You may find your problem goes away after some of these basics. If not, at least we know we're not wasting time on the them.
When posting any code on here please :
  1. Ensure you have Option Explicit set (See Require Variable Declaration).
  2. Try to compile it. If it doesn't compile for any reason please explain that clearly - including the error message and which line of your code it appears on. Compilation is done from the Visual Basic Editor menu - Debug \ Compile Project (Where Project is the actual name of your project).
  3. Copy your code (using the Clipboard - Cut / Copy / Paste) from your project directly into your post. Typing in code is not appreciated as it is likely to introduce typos which cause members to waste their time unnecessarily.
  4. Ensure that the code in your post is enveloped within CODE tags (For more on this see BB Code List). The hash (#) button in the posting page helps with this. Simply select your code and click on the hash button to have it enveloped automatically.
If all these points are covered then all members will be better able to understand, and therefore attempt to answer, your question.
Mar 26 '10 #3
colintis
255 100+
Thanks for the reply and corrections NeoPa, after setting the Variable Declaration and clicked compile, there's nothing happened and the compile button is disabled. Does it means the codes were fine?

MyDB from the upper part of the code is simply defined with:

Expand|Select|Wrap|Line Numbers
  1. Private myDb As Database
  2. ....
  3. Private Sub cmdArchive_Click()
  4. Dim DeactiveDate As String
  5. Dim Comment As String
  6.  
  7.     Set myDb = CurrentDb
  8. ....
  9.  
The attachment below is the error message I've been received, the error message was received when the code executed from .mde file, while executed in .mdb file there were no actions occured, stopping on the INSERT SQL line.
Attached Images
File Type: jpg error.jpg (26.3 KB, 368 views)
Mar 29 '10 #4
NeoPa
32,556 Expert Mod 16PB
@colintis
Generally, when the compile option is greyed out it means the code is already successfully compiled. This is a good status.

Otherwise, the error message seems to be pointing towards an issue with the configuration of the form - in that it doesn't like the procedure you linked to to handle the event. This may be due to security settings on an MDE. I'm not really sure.

When the code runs and stops on the myDB.Execute line, there should be an error message displayed there too. We're a bit stuck without that info to be fair. There is nothing obviously wrong I can see, but then I don't know your database. It could be something that cannot work within your database specifically.
Mar 30 '10 #5
colintis
255 100+
So in that case, the error is located somewhere outside the codes? but settings for both mdb and mde are using the default settings which its been working in previous versions(by other programmers before me) as well.

What other info would give the help that I can provide? I'll take a check again on the tables to see if there's any problems.
Mar 31 '10 #6
colintis
255 100+
Yes the problem is found on the target table with a column missing, i checked it with running the SQL in the query and it showed an error message about it. Thanks for your advise NeoPa
Apr 1 '10 #7
NeoPa
32,556 Expert Mod 16PB
@colintis
A pleasure to help Colin.

You probably understand better how hard it is to help in a more specific way when the error was in an area we had no information about.

Of course, it's often hard to know what information to include too, when you don't understand the problem. It's what makes it all so much fun :D

Anyway, I'm pleased you managed to find the solution :)
Apr 8 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James Bird | last post by:
Hello In order to perform a hetrogeneous join (I think that's what they're called) between MySQL and another database, I've created an Access database containing linked tables from each...
5
by: Philippa | last post by:
I'm trying to access data in vba using the openrecordset command. The data in on a SQL Server 2000 database, and I have linked tables to that data. the Table I'm trying to access is one of these...
1
by: annie | last post by:
Hi all, I have recently ported my Access 2000 app to SQL Server, keeping the Access client as the front end using linked tables. I am also using triggers on my SQL tables to trap orphan...
0
by: crypto_solid via AccessMonster.com | last post by:
I have been using a SQL database with a VB5 frontend for about 5 years. Works well. Unfortunately I don't have access to the source code. I was tasked with implementing a "job entry" application...
5
by: lottaviano | last post by:
I am using Access 2002 and have two tables (Main and Actions) linked (in Relationships) on one field "CAL_ID" (primary key in Main Table). Main Table is a list of equipment. Actions Table lists...
2
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
1
by: Lpitt56 | last post by:
I am running MS Access 2007 and I want to update an Outlook Address book from my Access Database. I started out by importing the Outlook Address Book as a linked table and it linked fine. I then...
3
by: nimajneb via AccessMonster.com | last post by:
Can anyone offer me any insight on the following problem? I have an Access database on a company shared drive. I'm the designer and the only user (so far). Suddenly, any time I try to open a...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
10
by: MeeMee | last post by:
Hi I have a problem appending data into an oracle table from access. I imported the new data from an excel sheet into a table in access and useed an append query to add the data into a linked...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.