Unsuccessful Execution Of SQL Statement Within VBA Codes

Jan 1, 2006

I have a problem about running SQL statement in VBA code. I will appreciate a looot if you can help me solve the problem ASAP.

I tried to run the following statement in my VBA code to update a table in my database:

DoCmd.RunSQL "UPDATE TBL_GRANTBASEDATA, TBL_QUARTER SET TBL_GRANTBASEDATA.Retire_QTR = TBL_QUARTER!QUARTER WHERE ((([TBL_GRANTBASEDATA]![Retire_Date])<=[TBL_QUARTER]![End_Date] And ([TBL_GRANTBASEDATA]![Retire_Date])>=[TBL_QUARTER]![Start_Date]));"

It turns out that the table will not be updated if I run the above SQL statement with my other VBA codes. (ACCESS doesn't give any error messages even though the database was not updated.) But if I run the SQL statement by itself rather than within the other codes, the database will be updated successfully. (When I set a breakpoint at the above SQL statement and run it manually within the other codes, the database are updated successfully too.)

Apparently, the SQL statement and the other codes don't have any syntax errors. I wonder why ACCESS doesn't execute the SQL statement when the SQL statement is put within the other VBA codes. Is it because the table it tried to manipulate was locked by the other codes?

The following are all the VBA codes including the SQL statement I'm talking about. When I run the following codes together, the database is not modified by the SQL statement (the last sentence). But if I run the last sentence and the other codes separately, the database was modified successfully.


Dim rstDataLoad As New ADODB.Recordset
With rstDataLoad
Set .ActiveConnection = cnnSHELL
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Source = "SELECT TBL_GRANTBASEDATA.* FROM TBL_GRANTBASEDATA;"
.Open
End With

'Calculate Retire_Date
rstDataLoad.MoveFirst
Do While Not rstDataLoad.EOF

Calculation omitted.

rstDataLoad.MoveNext
Loop
rstDataLoad.UpdateBatch
rstDataLoad.Close
Set rstDataLoad = Nothing

DoCmd.RunSQL "UPDATE TBL_GRANTBASEDATA, TBL_QUARTER SET TBL_GRANTBASEDATA.Retire_QTR = TBL_QUARTER!QUARTER WHERE ((([TBL_GRANTBASEDATA]![Retire_Date])<=[TBL_QUARTER]![End_Date] And ([TBL_GRANTBASEDATA]![Retire_Date])>=[TBL_QUARTER]![Start_Date]));"

View Replies


ADVERTISEMENT

Generate Data Based On Zip Codes Or Area Codes

Feb 28, 2008

Hello Don,

View 13 Replies View Related

Want To Stop Execution!

Feb 12, 2006

i have created a new utility DB that has only one form..when it opens I set the startup form "Main" and on the OnOpen event of this form I have some code to open another database and close this one...

this means that whenever i open this database, it opens, opens up the other one and this utility DB closes...and i cannot access it coz it always opens and closes automatically...how can I stop it from executing to be able to edit its VB code?!

Thanks, this is driving me mad !

View 2 Replies View Related

DTS Execution Via MS Access

May 23, 2007

Hi Folks,

I am wondering if it is possible to execute a DTS package via Microsoft Access. I have done a bit of research and cannot seem to really find anything that claims this is possible or how to go about to get it to work. I am running SQL Server 2000 which has quite a few DTS packages ... it would be really neat if I could just create a small interface in Access whereby a form has a few buttons on it that can be clicked and the DTS packages can be executed on the server, this way folks won't need to log on to the server and run the DTS packages via SQL Server Enterprise Manager. What would REALLY be awesome would be if values can be passed between SQL and Access but I think if that is possible it would be quite an animal to achieve (I know it is possible via Visual Basic programming but not really worth all the work to create an independent program just to run a DTS package or pass a value). If anyone can provide me with any information or where to look I would appreciate it.

Thanks,

Joe

View 3 Replies View Related

Form Execution Bug

Jul 3, 2005

Hi everyone,

This is my problem. Almost all the time(90%), I open the main form of my application and a large part of the form is blank(white). If I open it from the Database window it often work well and all the form is visible.

When the bug occur, If I just switch from Access to another application like Internet Explorer and I come agian to Access then all the form is visible.

Is someone ever seen that kind of bug. What that can cause that problem. How can I solve it?

N.B. There is a lot of controls on my form and I guess that bug can be linked with it. Seems like Access is trying to open my form too rapidely.

View 1 Replies View Related

Query Execution Time

Jan 3, 2006

I have a query, it joins a local table to a remote table (Oracle Database Table) which makes it slow(ish).

When I am in design mode and i click the "View Datalist" button, which visually shows me the results, the query executes in about 12 seconds.

When I use the "!" Button to physically Execute the Make-Table Query, it takes hours.

What things should i look for that might cause this problem? Where do I need to optimize.

To me it seems rather odd that the query would execute so fast when i view the data than when it physically executes the data.

Same speed problems when i just run the query as a Selection Query as opposed to the Make-Table Query, so it's not an issue of writing to disk/etc.

View 2 Replies View Related

Time Execution Question

Mar 14, 2005

Hi,

how can i create a comand button that open a form at predifined date?

example: if current date=2005/14/12(yyyy-dd-mm) then open form "example"


thnks,
Kopas

View 4 Replies View Related

Wait For Shell Execution To Finish?

Jun 19, 2007

I'm using hte Shell() function but this doesn't wait for the executable file to finish so I'm looking for a command line function that would wait until the executable file is finished executing...

I saw this function WaitFor but it is not supported in MS-Access? So, what do I do?

Thanks...

View 7 Replies View Related

Modules & VBA :: Call Value From A Text Box During SQL Execution

Dec 20, 2014

I have this segment of code that adds data to fields FName and FPath in the table Files. It works fine but the syntax is a nightmare with all the double quotes and symbols.

Code:
strSQL = "INSERT INTO Files " _
& " (FName, FPath) " _
& " SELECT """ & strTemp & """" _
& ", """ & strFolder & """;"
CurrentDb.Execute strSQL

I have another field in the table Files called CompletedBy that shows who updated the table (they type their name into a textbox Text1 before clicking a command button to run the code). I would like to add this data to the table during the execution of strSQL. All the records added to the table Files will have that value in the CompletedBy field (say, Bob Jones).I tried the below changes but the code doesnt work.

Code:
strSQL = "INSERT INTO Files " _
& " (FName, FPath, CompletedBy) " _
& " SELECT """ & strTemp & """" _
& ", """ & strFolder & """ & Me.Text1 & """;"
CurrentDb.Execute strSQL

How would I add a value in field CompletedBy, from the textbox Text1, to all records added to table Files when the code is run?

View 2 Replies View Related

Query Execution And Record Modifying

Dec 8, 2014

whenever I run/execute a query in Access it is modifying the first record on the table in which it is calling the data from.For example if the first record might contain the following:

Record A: John Doe, Oct, 2014, Account is Active

And lets say I am running a query to pulling records from Nov 2014.The Month and Year Fields in the above example for Record A gets modified to the query search parameters for Nov.Is there some of of record lock or controls that I need to adjust to prevent this from occurring?

View 1 Replies View Related

Disable Datasheet From Poping Up After Query Execution

Sep 24, 2007

I am trying to take input for my reports based on a query result dynamically for which i dont want to display the Datasheet after the execution of Query ,inturn i am displaying results in Report. Any help on this would be appreciated.

View 14 Replies View Related

How To Stop Query Execution At The Form Start

Dec 19, 2005

Hi

I am a new user to Access. I created couple of forms using wizard, but when I view them, they show me all the available data by default. I want to stop this, if anyone can help me plz.

RMA

View 5 Replies View Related

Forms :: How To Force Execution Of A Query When Changing Record

Jul 13, 2014

I have the following tables:

Supplier
Supplier# [Other columns]

Material
Supplier# Material# [Other columns]

DeliveryHeader
Delivery# Supplier# [Other columns]

DeliveryDetail
Delivery# Supplier# Material# [Other columns]

I've created a form based on table DeliveryHeader with a subform based on table DeliveryDetail. The two are linked by Delivery# Supplier#.

On the form, Supplier# is a combobox that lists all suppliers from table Supplier.
On the subform, Material# is a combobox that lists only the materials supplied by the supplier selected with form's Supplier#.

The problem is that this second list always shows the materials of the first listed supplier. For instance, when the form is loaded, it shows delivery #1 with all its details on the subform. Suppose supplier loaded to form is #1.

1) If I use subform combobox, it shows correctly supplier's #1 materials. But then, whatever delivery I navigate, it always shows supplier's #1 materials.

2) If I navigate to another delivery without using subform combobox, suppose I stop on a delivery where the supplier is #4, then subform combobox shows correctly supplier's #4 materials. But then, once again, whatever delivery I navigate, it always shows supplier's #4 materials.

I've spread Me.Requery here and there but without any success. What trick must I apply to force the execution of the query of the subform combobox Material# each time I navigate to a new record on the form?

View 4 Replies View Related

General :: Pop Up Process Running MsgBox And Close Automatically On Execution

Aug 23, 2013

I have a form that loads when the database is open, and the form has buttons etc. that leads to queries and reports in the database. (Queries open in a form). Since most queries take a while to load, I was wondering if there is a way to Pop up a message box stating "Please Wait, Query is running..." (or something like that), and once the form opens the MsgBox should close automatically. (The user should not have to hit Ok button.)

Most users of this database would have restricted access such that they would not have navigation pane and toolbar visible - hence I want to make it a touch more interactive when a process is running...also if someone is new to access they might not notice that taskbar status and I don't want them thinking the program is stuck etc..

View 4 Replies View Related

Modules & VBA :: Excel File Opens And Code Stops Execution

Nov 12, 2014

I'me running on Win7, Office 2010, Acc2003 format (.mdb), writing data to Excel 2010 (.xlsx)I have code to create an Excel file, send record set data to it, and then add some formulas and formatting. I was trying to tune up the formulas, when I got a pull back:Access VBA code suddenly stops running, and the file gets displayed in Excel

Code:
'ApXl is Application.Excel
'xlWSh is the Excel WorkSheet
'rst is my DAO.Recorset

[code]...

The same happens when I have ApXl.Visible = True

View 10 Replies View Related

Zip Codes

Jun 5, 2006

I have a table that contains a Zip Code field. Some of the Zip Codes are missing the leading 0. Zip Codes are a 5 digit field and these codes only have four. how do I get Access to recognize the number of characters and then add the leading 0 to only the ones that have 4 numbers?

Thanks

View 1 Replies View Related

Zip Codes

Jan 18, 2007

Has anyone had any dealings with a way to calculate distance between 2 zipcodes? Of course all the zips wouls be in the current DB.... Then need to query those within a certian distance of another zipcode. I have a feeling this will need to be linked to an external source or app........ BUT... Anybody have any experience with anything similiar?

View 5 Replies View Related

Bar Codes

Apr 9, 2007

I would like to print a bar code on my invoices and then have my delivery drivers run the invoice under a bar code reader when they return from delivering. I know how to print the bar code I am nit sure how to go about interfacing a bar code reader in access 2000. Any thoughts?

View 3 Replies View Related

Codes And Descriptions

Jul 25, 2005

Hi i have designed a database where the users use a combo box to find a particular code they want..for example dog_brown or dog_grey, on the report which i have produced this code for the type of dog shows up to. I have another table which has a column with the code and also the description...eg dog_brown...brown dog. My users have asked me if on the report which i have produced can the description be shown instead of the code. I dont know if this can be done...any help would be grateful. Thanx

View 3 Replies View Related

VBcolor Codes

Oct 21, 2005

I was wondering where I might get a list of code I can use to change text in my program. If there is no list what would I use to get dark green. Right now I am using the following:


[description of failure].ForeColor = vbGreen

Thank you

roborro

View 2 Replies View Related

The Question Of Too Many Codes?

Apr 25, 2007

I have been wanting to ask this question for long. Is it alright to put too many codes in the various events of the forms and controls? Will it affect the efficient functioning of Access? Will those codes result in any absurd behaviour? For example, I have DMax function in the BeforeInsert of form followed by three If....End If codes. I have not faced any problem so far. However, I just want to hear the opinion of the experts.

View 1 Replies View Related

Tables - Need Codes?

Jun 27, 2007

Hi, I have the following problem.

I have three tables, Main Table, Table A and Table B. All three tables have a field called "Cutoff Time". The Main Table will look up the info from Tables A and B. Table A has a field called "Service". In the main table, there is also a field called "Service", which is same as the field in Table A. The condition is this: The main table should use the "Service" field to match the "Service" field in Table A to get the "Cutoff Time" from Table A. If there is no such match, then the "Cutoff Time" will be taken from Table B using another field called "Station".
I was wondering, how can I perform such an operation? Do I need to write SQL statements?

Thanks in advance!

View 1 Replies View Related

I Need Help With My Expression Codes...

Feb 23, 2006

I would like the textbox named "text7" to show the word "keswick" when the text inside the "txtUsername" is KH and show the word "Lawrence" when the text inside the "txtUsername" is LH. What sort of codes should I write? should it be SQL or Expression Builder or Code Builder? Thank you=)

View 2 Replies View Related

About MS Access And Color Codes

May 11, 2006

Sometimes the simplest of questions can be the hardest to find the answer to. I have spent the last 2 hours searching for the answer to this one. I'm sure it's on this site somewhere but the search is running way to slow for me to be of any use.

What exactly does the numeric color codes in VBA represent? I have downloaded a score of color pickers. utilities and none use these numbers in the way Access does. Ideally, I'd like to find a utility that will allow me to specify a particular color and then give me the corresponding code for that color.

TIA

View 2 Replies View Related

Access Error Codes

Jan 23, 2008

Does anyone out there have any ideas on how I can get a full list of the error codes and their descriptions for microsoft access?

I've set up a simple table with two fields, one for the error code and the other for the description. I've written a short bit of code (see below) to build the table for me, but it only generates 88 codes with the highest being 746.

Now I know that there are error codes up in the 3000 area because I'm trapping a few of them.

What I'm looking for is a list of the error code so I may write an extended list in my error trapping routines.


Code as follows:

Private Sub Form_Load()
Dim My_RecordSet As DAO.Recordset, My_DataBase As DAO.Database
Dim My_Error As Long
Dim My_Description As String

For My_Error = 0 To 4000

On Error Resume Next

Err.Raise My_Error
My_Description = Err.Description

If My_Description <> "" Then

If My_Description <> "Application-defined or object-defined error" Then

Set My_DataBase = CurrentDb
Set My_RecordSet = My_DataBase.OpenRecordset("ErrorCode_Table", dbOpenDynaset, dbAppendOnly)
With My_RecordSet
.AddNew
![ErrorCodes] = My_Error 'set error #
![ErrorString] = My_Description 'set error description
.Update
.Close
End With

End If

End If

Next My_Error

End Sub



Cheers muckers

D

View 3 Replies View Related

Input Mask For Zip Codes

May 23, 2005

I am working on a membership database that only has members from Canada and the United States. In the zipcode field, is it better to have two seaparate fields or is there an input mask that can handle both US and Canadian zip codes.

Thanks in advance.
24t42

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved