First, apologies for all the code; I'm not sure what is most relevant to my problem.
I am trying to use the code below to select Records from an Access table called [Client_Details] and insert them into another table (in the same database) called [ClientMailMerge Selection]. Once there I will then run a mail merge operation.
The problem is, no Records are being inserted and no error message is ever displayed.
I have inherited the code and am effectively stuck with it, so suggestions for obvious errors in the existing code preferred please. I have little knowledge of SQL or VBA
Oh, and I am using Access 2002, but the database is formatted as Access 2000.
Many thanks for any help you can offer. -
Private Sub btnSearch_Click()
-
Dim rcsLookUp As Recordset
-
Dim SQLOrderBy As String
-
Dim lCount As Long
-
-
On Error GoTo Err_btnSearch_Click
-
DoCmd.Hourglass True
-
DoEvents
-
-
SQLQ = "INSERT INTO ClientMailMergeSelection "
-
SQLQ = SQLQ & "(CaseID, REF, E_DATE, SNAME, INITIAL, INITIAL1, TITLE, "
-
SQLQ = SQLQ & "Sal_Too, Sal_Dear, ADD1, ADD2, ADD3, ADD4, PCODE, "
-
SQLQ = SQLQ & "TEL, Email, HouseNumber, Flat, HouseName, StreetLine1 )"
-
SQLQ = SQLQ & "SELECT "
-
SQLQ = SQLQ & "Client_Details.CaseID, Client_Details.REF, Client_Details.E_DATE, Client_Details.SNAME, "
-
SQLQ = SQLQ & "Client_Details.INITIAL, Client_Details.INITIAL1, "
-
SQLQ = SQLQ & "Client_Details.TITLE, Client_Details.Sal_Too, "
-
SQLQ = SQLQ & "Client_Details.Sal_Dear, Client_Details.ADD1, "
-
SQLQ = SQLQ & "Client_Details.ADD2, Client_Details.ADD3, "
-
SQLQ = SQLQ & "Client_Details.ADD4, Client_Details.PCODE, "
-
SQLQ = SQLQ & "Client_Details.TEL, Client_Details.Email, "
-
SQLQ = SQLQ & "Client_Details.HouseNumber, Client_Details.Flat, "
-
SQLQ = SQLQ & "Client_Details.HouseName, Client_Details.StreetLine1 "
-
-
SQLQ = SQLQ & "FROM Client_Details "
-
-
SQLWhere = ""
-
-
If ComboLender <> "" Then
-
SQLWhere = "LenderID = " & ComboLender.Column(0) & " "
-
End If
-
-
' status
-
If Not IsNull(ComboStatus) Then
-
If SQLWhere <> "" Then SQLWhere = SQLWhere & "AND "
-
SQLWhere = SQLWhere & " Client_Details.[STATUS] = '" & ComboStatus & "' "
-
End If
-
-
If ComboMedia <> "" Then
-
If SQLWhere <> "" Then
-
SQLWhere = SQLWhere & "AND "
-
End If
-
SQLWhere = SQLWhere & "Media_ID = " & ComboMedia.Column(0) & " "
-
End If
-
-
' security type
-
If Not IsNull(ComboSec) Then
-
If SQLWhere <> "" Then SQLWhere = SQLWhere & "AND "
-
SQLWhere = SQLWhere & "[client_details].[sec] = " & ComboSec & " "
-
End If
-
-
If txtDateFrom <> "01/01/1998" Or txtDateTo <> Date Then
-
' only do date checking if theye have changed the dates otherwise
-
' no point we just get em all
-
If Not IsNull(txtDateFrom) And Not IsNull(txtDateTo) Then
-
If Not IsDate(Me.txtDateFrom) Then
-
MsgBox "Invalid 'From' date", vbOKOnly + vbExclamation
-
Me.txtDateFrom.SetFocus
-
Exit Sub
-
End If
-
If Not IsDate(txtDateTo) Then
-
MsgBox "Invalid 'To' date", vbOKOnly + vbExclamation
-
txtDateTo.SetFocus
-
Exit Sub
-
End If
-
If SQLWhere <> "" Then SQLWhere = SQLWhere & "AND "
-
Select Case Frame51.Value
-
Case 1
-
SQLWhere = SQLWhere & "[E_Date] "
-
Case 2
-
SQLWhere = SQLWhere & "[Statusdate] "
-
Case 3
-
SQLWhere = SQLWhere & "[Date2] "
-
End Select
-
SQLWhere = SQLWhere & "BETWEEN #" & Format(txtDateFrom, "mm/dd/yyyy") & "# "
-
SQLWhere = SQLWhere & "AND #" & Format(txtDateTo, "mm/dd/yyyy") & "# "
-
End If
-
End If
-
-
If SQLWhere <> "" Then
-
SQLWhere = "WHERE " & SQLWhere
-
End If
-
SQLOrderBy = "ORDER BY REF"
-
-
CurrentDb.Execute "DELETE * FROM ClientMailMergeSelection", dbFailOnError
-
CurrentDb.Execute SQLQ & SQLWhere & SQLOrderBy, dbFailOnError
-
Me.ClientMailMergeSelection.Form.Requery
-
DoEvents
-
DisplayHeadings
-
DoCmd.Hourglass False
-
DoEvents
-
Exit Sub
-
-
Err_btnSearch_Click:
-
MsgBox Err.DESCRIPTION
-
Resume Next
-
-
End Sub
2 3381 NeoPa 32,579
Recognized Expert Moderator MVP
I think we can help some. There may be a few things to deal with though, including some work for you to do finding info (we'll help here too of course).
I'll start with some advice about preparing and posting your code. If after trying to compile you find any issues you cannot deal with then let us know (with details) and we''l help you sort it out.
It is always a good idea to ensure that variable name checking is enabled, AND your code compiles (at least compilation has been attempted), before submitting a question (Require Variable Declaration).
This avoids asking questions which are much more easily resolved on your own PC than on a forum.
To ensure variable name checking is enabled for all new modules, go to - Tools / Options / Editor (from the VBA Editor window) and set Require Variable Declaration to True (checked). For existing modules, ensure that the Option lines at the very top include : NeoPa 32,579
Recognized Expert Moderator MVP
Moving on, and assuming that you had no problems with the earlier post and have changed your code accordingly, let's look at the SQL that's created within your code and run it from within a QueryDef (saved Access query). That way, purely for testing/debugging purposes, we can see what the error messages may be. If there is none, then we can at least explore further by tweaking it more easily.
What I want you to do is to stop the code at line #86 (See Debugging in VBA for help with this) and display the contents of the variable SQLQ into the Immediate Pane of the Visual Basic Editor window. I can't see what type of variable SQLQ is (this was the main reason for my earlier post btw). When it is displayed in there I would like you to Copy it into the clipboard and Paste it into a new QueryDef (Create a new QueryDef - Insert \ Query from the Menu, Select SQL View - View \ SQL - from the menu, Paste in the value from SQLQ you copied earlier). If you run this from the Database window then you should see some messages displaying what is happening. Post this here so that we can give it some consideration.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: lawrence |
last post by:
I'm not sure how this is normally done, on a large site, perhaps one
running Phorum. Occassionally a thread will have hundreds of entries,
perhaps a meg or two worth of data. You won't necessarily print all
that to the screen, but PHP has to hold it in memory. Run some
operations on it, or, more likely, have an array that you keep adding
things to, and very soon you run into the 8 meg limit that is the
default limit for PHP scripts.
...
|
by: serge |
last post by:
I have a scenario where two tables are in a One-to-Many relationship
and I need to move the data from the Many table to the One table so
that it becomes a One-to-One relationship.
I need to salvage the records from the many table and without going
into detail, one of the reasons I can't do the opposite as
there are records in the ONE table that I need to keep even if they
don't have any child records in the MANY table.
Below I created...
|
by: nicver |
last post by:
I am fixing a client's Web site and for some reason an ASP class does
not want to use the variables it retrieves when it initialiases.
This is an excerpt of the class and it is enough to show what is not
working correctly:
------
Class clsAd
private pintMyData1
private pintMyData2
private pintMyData3
|
by: mp |
last post by:
I have example like follows:
OleDbCommand InsertCommand =
new OleDbCommand("INSERT INTO RecnikTable VALUES (@ENGLESKI, @SRPSKI)",
thisConnection);
InsertCommand.Parameters.Add("@ENGLESKI", OleDbType.VarChar);
InsertCommand.Parameters.Add("@SRPSKI", OleDbType.VarChar);
string reci = {textBox2.Text, textBox2.Text};
InsertCommand.Parameters.Value=reci;
|
by: nicholas |
last post by:
To insert a record in a Ms Access database and be able to retrieve the newly
created ID (autonumber) I used the code below (code 1).
Now, the problem is that this is not very secure and that, if for example an
insertion contains a ' or a " this code fails. It is much better to work
with @parameters.
So could someone change my code to make it work with @parameters and that I
still can retrieve that autonumber. (note that it is for a MS...
| |
by: Howard Kaikow |
last post by:
I got bored today, so I decided to rewrite the code in KB article 316383 to
decrease the number of object references.
This resulted in a number of nested With ... End With.
The original code had a
Dim r As Integer, c As Integer
shortly before a For Next.
|
by: anachronic_individual |
last post by:
Hi all,
Is there a standard library function to insert an array of characters
at a particular point in a text stream without overwriting the existing
content, such that the following data in appropriately moved further
down? From a cursory search of the libc documentation I can't find such
a function. Will I have to write it myself?
Thanks.
|
by: Iain |
last post by:
I have the following .net page with a pushbutton in a datagrid. This
pushbutton should delete the selected record.
It works in the same manner in many other pages of the same format (I
actually copied and pasted most of this code from another form).
Can anyone enlighten me please as to why this happens randomly and how
to evercome it as It is driving me nuts.
Thanks in advance for any assistance offered
|
by: =?Utf-8?B?bXBhaW5l?= |
last post by:
Hello,
I am completely lost as to why I can't update a DropDownList inside a
DetailsView after I perform an insert into an object datasource. I tried to
simply it down to the core demostration:
default.aspx:
|
by: daJunkCollector |
last post by:
Hey, I have a simple web app that requires the user to click a text link to add a section to the form. As you will see from the following code (PHP/mySQL), the link inserts a row into the database table. The problem is that, during testing, sometimes when I click the link, two rows are added instead of only one. I only want one row to be added. Could you please help me figure out my bug?
// Insert and delete actions for Education, Work...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |