An Apostrophe Is Causing Problems While Inserting!

Mar 24, 2008

Hi,

In my database if the user wants to change a record, I make them store the old record in another table. I am using the following code.


Private Sub cmdArchive_Click()

On Error GoTo ErrorHandler
Dim conn As ADODB.Connection
Dim i As Integer
Dim s As String
Dim sSQL As String

sSQL = "INSERT INTO tblNamesArchive ( txtGivenName, txtSurname )" _
& "VALUES ( '" & txtGivenName & "', '" & txtSurname & "');"

Debug.Print sSQL
Set conn = CurrentProject.Connection
conn.Execute sSQL
GoTo ThatsIt
ErrorHandler:
Select Case Err.Number
Case -2147217908 'command text not set
Case -2147217865 'cannot find table
Case 3021 'no records
Case Else
MsgBox "Problem with cmdArchive_Click()" & vbCrLf _
& "Error " & Err.Number & ": " & Err.Description
End Select
ThatsIt:
conn.Close

End Sub


I have no problems making the following code work except if there is an apostrophe " ' " in either the txtGivenName or txtSurname . For example O'Keefe it shows an error but not O"Keefe! How do I fix this?


Thanks

Raghu Prabhu
Melbourne.

View Replies


ADVERTISEMENT

Apostrophe

Nov 2, 2004

For example, if I'm coding an insert manually, if I need to insert a string from a textbox, I have to do something like this

mycn.execute "Insert into Test(FName,LName)values('" & me.text1 & "','" & me.text2 & "')

I have to put a ' at the end of each string values

Is there any way to bypass this? I mean I could put a validation code and each time I detect an apostrophe I handle it so that it doesn't create a problem

But I mean a simple way to bypass this

View 2 Replies View Related

Alphabetizing - With An Apostrophe

Apr 2, 2005

Hi, I may be dense, but I cannot find an answer to this question anywhere. If it has a simple and obvious answer, my apologies.

I have created an index with a field called "Surname" -- I need to know how to force Access to alphabetize the names disregarding the apostrophes (or a space) - for example, O'Brien. The way it works now, all the O' (s) go at the beginning of the Os (O'Brien, O'Malley, O'Neal, Oakley). I want it to go - Oakley, O'Brien, Oddfellow, O'Malley.

Is there a way to do this and still display the apostrope? I feel that I could set something for the field in the design view, but for the life of me I can't figure it out.

Thanks in advance for any help. :)
Jeri

View 1 Replies View Related

Apostrophe In Target Db Name Throws Error

Dec 14, 2007

sql = "SELECT Table1.* INTO Table1 IN '" & sExpFileName & "' FROM Table1"
CustDB.Execute sql

where the sExpFileName contains the path of The Target MS Access DB
The Query works fine. But recently I discovered that if my target File name contains apostrophe It gives error as Query Input must contain at least one table or query

Is there any way to solve this problem. Please suggest me some way

View 7 Replies View Related

Error When Trying To Insert String With Apostrophe

Apr 27, 2005

Hey, I have a problem with my application......when the user trying to insert string with apostrophe into txtDesc (text box), the code returns error...

Run-time error '3057'

the database inserts any records excellently, but not with the apostrophe....

here is my code:
Code:sql = "INSERT INTO M_Stock ([StockRef], [StockGroup], [Desc], [Location], [Category], [UOM], " & _ "[RQ], [Remark0], [Remark1], [Remark2]) " & _ "VALUES ('" & txtStockRef & "', '" & cmbSG & "', '" & txtDesc & "', '" & cmbLoc & "', " & _ "'" & cmbCat & "', '" & cmbUOM & "', '" & txtRQ & "', '" & txtRemark0 & "', " & _ "'" & txtRemark1 & "', '" & txtRemark2 & "');"Set dbs = CurrentDbdbs.Execute sql

Can someone help me with this problem? Thanks in advance

View 1 Replies View Related

Queries :: Syntax Error When Name Contain Apostrophe

Mar 3, 2014

I have a query written in Visual Basic as follows

UA1 = Forms(ParName).Form.NOM
UA2 = Forms(ParName).Form.PRENOM
UA3 = Forms(ParName).Form.CARTE
Forms(ForName).Recordset.FindFirst "[NOM] = '" & UA1 & "'" & " And " & _
"[PRENOM] = '" & UA2 & "'" & " And " & _
"[CARTE] = '" & UAE & "'"

This query works and I can spot the record based on 3 fields and display it. Now I have discovered that we have a person who has an apostrophe in his name like O'Brian. The above code gives a syntax error in this case.

View 3 Replies View Related

Queries :: Add Apostrophe To Mixed Data?

Jan 9, 2014

I am combining fields one that has apostrophe's and the other does not. exp "if this field is null use data from this field (which does not have an apostrophe) otherwise use current field (which has apostrophe)

"red"
blue
orange
"yellow"

How can I change that in the query without changing the previous query to

"red"
"blue"
"orange"
"yellow"

View 2 Replies View Related

Find Keycode To Apostrophe / Quotation Key

Oct 28, 2014

I have a Dell keyboard at work and I am trying to find the keycode to the apostrophe/quotation key. I want to disable this when pushed with the ctrl key. I've searched online but could not find anything that shows that specific key. I only see apostrophe keys or quotation keys but not the combination of both which is what I have.

View 4 Replies View Related

Insert Error Due To Apostrophe - Syntax Needed

Jul 20, 2006

hi,
i am getting an error in my coding for a INSERT statement becasue the text of the field contain an apostrophe.

that is my code is

DoCmd.RunSQL "INSERT INTO tbl_StartEndDates_OVERHEAD ( Last_Name)" _ & "VALUES ('" & Forms!OverheadEmployeeDates!lblLast_Name & "');"

but the text in Forms!OverheadEmployeeDates!lblLast_Name is "D'Amereo".

I know that this works for all other Last_Names without an apostrophe in it

does any one know the correct coding for this?

thansk
tuk

View 3 Replies View Related

Forms :: Open Form By Name Not Reading Apostrophe

Mar 17, 2014

I have a button in one form that opens a different form and want it to show specific data to display. I choose this option in the command button wizard and set it up to have the name from my main form be the same name as my new form to be opened. Everything works perfectly until I choose a name that has an apostrophe in it. So if I choose the name "Ender's Game" it gives me the alert:

"Syntax error (missing operator) in query expression '[bookName]='Ender's Game".

I think I've found where the problem is, I just can't figure out how to fix it. When I looked at the onClick embedded macro it has the Where Condition as:

=="[bookName]= & "'" &[BookName] & "'"

Is there a way to get Access to accept that an apostrophe in the name is meant to be part of the string itself?

View 7 Replies View Related

Forms :: Filter A Report Based On Listbox Selection - Apostrophe In Results

Feb 17, 2014

I use the follwing code to filter a report based on the listbox selection on a form. Below is the code I use, the problem it will error if the results have an apostrophe in the string.

Private Sub FilterDesc_Click()
Dim strWhere As String
Dim ctl As Control
Dim varItem As Variant
'make sure a selection has been made
If Me.ListCarrier.ItemsSelected.Count = 0 Then
MsgBox "Must select at least 1 Carrier"

[Code] ....

View 7 Replies View Related

Causing A Headache

Sep 28, 2006

I have a main form [mainform] with several subforms on it, two of which are on a tab.

On the second tab [page79] there is a subform [subformlist] which has like 25 checkboxes on it, any combonation of which can be picked by the user.

I need there to be at least one pick required of this subform, else the record won't show in a general query I have, since the table the subform is based on is linked to the record.

Is there anyway to make making a choice of one of at least one of these checkboxes checked a manditory thing before the user can close or move on to the next record?

I've tried making an "Other" box that on the Table has a default value of "True" which I thought would cause it to show in the query record...to no avail.

The only true way to make this work is to have it mandatory that the user pick from AT LEAST one, usually more before the record is complete.

Any help? Other than writing a MASSIVE If...Then statement...?

Or is there a way to make it so the choice isn't required for the record to show up in the query?

I'd post...but my db is too massive, even zipped.
:(

View 2 Replies View Related

Coding Causing Confusion - To Me

Apr 20, 2006

Yesterday I posted a question and rec'd good advice but as usual I don't think I explained myself very well.
As the attached picture of my Form shows, I have a checkbox for each Age Group under each Team. I originally had a query that would come up for each Team's particular Age Group and then the required data copuld be input. This leads to too many querys clogging things up. I tried to copy the SQL code of one of the query's to the On_Click event of the checkbox but as I have been informed SQL is different to VB.
All I would like to know is how to convert the SQL to VB coding so that I can continue to do the coding for each Checkbox.
The SQL code for the first checkbox is:

SELECT tblPlayerRegister.Surname, tblPlayerRegister.[First Name], tblPlayerRegister.Age, tblPlayerRegister.[D'n], tblPlayerRegister.G1, tblPlayerRegister.SP, tblPlayerRegister.Age2, tblPlayerRegister.G1A
FROM tblPlayerRegister
WHERE (((tblPlayerRegister.Age)<11) AND ((tblPlayerRegister.Club)="Beaconsfield"))
ORDER BY tblPlayerRegister.Surname, tblPlayerRegister.[First Name];

If there is an easier way, by all means let me know.
Any assistance would be greatfully appreciated.

View 1 Replies View Related

Conversion To .mde Causing Trouble!

Sep 26, 2006

I have a DB in .mdb format which works perfectly and when all the code is compiled it results in no problems. However. When I convert this to a .mde file, it doesn't work at all and it suggests that there are compile errors where there weren't any before! Please can anyone suggest what the problem might be as I don't particularly want to run this as a .mdb. Thanks

View 2 Replies View Related

Date Format Causing Problem

Aug 4, 2005

I have got the following query but when it actually inserts the date, the dates will be "08/01/2005". Month and day will be swapped if date is less than 12. I don't know it's happening. It's driving me crazy.

INSERT INTO P_Timesheet ( WeekNo, StaffID, StartTime, FinishTime, TotalHours, ADate, StaffActivityID, DateFilled, NotesByStaff )
VALUES (0, 'S24', #10:00:00 AM#, #11:00:00 AM#, 1, #1/08/2005#, 158, #21/08/2005#, '');

It will insert "8/01/2005" for the first date and "21/08/2005" for the second date. my date format is set to australia and i have set the same in my asp page as well. it is giving the same result even if i try direct from the query.

View 2 Replies View Related

Query Causing Problem With Dates

Sep 26, 2005

ok i have a query with 2 fields,

Endtime: AccountTime
Starttime

both date input from another query, if i run without any criteria it works and get some results:

Endtime Starttime
9/6/2005 6:24:09 AM9/6/2005 6:23:53 AM
9/6/2005 6:24:16 AM9/6/2005 6:21:20 AM
9/6/2005 6:24:34 AM9/6/2005 6:24:22 AM
9/6/2005 6:26:06 AM9/6/2005 6:25:51 AM
9/6/2005 6:26:15 AM9/6/2005 6:25:00 AM

and i have some inputs on a form (type - genreal date) with the values:
startdate:
09/06/2005 00:00:01
enddate:
09/06/2005 23:59:59

and the condition is on starttime field:
Between [Forms]![Main]![startdate] And [Forms]![Main]![enddate]

but i get no results....????

any help?
thanks in advance.

Dal

View 1 Replies View Related

Pass-through Query Causing An Error

Jan 4, 2006

I have a VERY simple select statement that I am using in a pass-through query: "SELECT * FROM dbo_vReturn;", but I cannot get this to work. Each time I run the query it generates an error: "ODBC call failed - Invalid object name "dbo_vReturn" (#208)".

The dbo_vRteturn is a view in the backend. I can open this table/view from Access using an ODBC connection but when I try to run the pass-through query it falls over!

Does anyone have any idea what is causing this?:confused:

View 2 Replies View Related

Trim Text Box Causing Error?

Jul 6, 2006

Hi all, this is my first post, I'll try and make it a good one :-)

System:
Windows 2000
Office 2000

I have a small network of PC's here which have access to our central database. I have a simple form created using the label wizard which is used to print address labels for mailing lists.
On most of the PC's here it works fine but on one or two (which have no obvious difference in thier setup) I get an "ODBC--Call Failed" error and it won't run the report????
I have puzzled over this for a while when I decided that I would remove the Trim function from the lines of the address fields on the label, these are put in automatically by the label wizard. This stopped the error message and the reports now run.
I don't know why this is happening but I am hoping someone will.

Thanks,

Matt.

View 6 Replies View Related

DSNless Connection Causing Error....

Dec 15, 2005

I am forced to switch from a DSN connection to my database to a DSNless connection by my hosting company. I changed my connection string from this:

strConn = "dsnname"
set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open strConn

to the following:

set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:pathtodatabasemydb.mdb;"

I connect fine. But when I run a certain query, I get the following error:

Microsoft JET Database Engine error '80040e14'

The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

The SQL statement in question here is:
SELECT MAX(week) AS LAST FROM Schedule WHERE Result <>''

If I change my connection back to the original DSN connection, everything is fine once again.

How would a different connection produce an error, and more importantly, how do I fix it?


Thanks,
Ted

View 3 Replies View Related

Compact And Repair Causing, Not Solving, Problems!

May 10, 2007

I have a large application in Access 2003 which comprises a main program file and 4 linked data files which between them contain around 50 tables. The prog file sees the data files through linked tables. Everything works well until I do a compact and repair on the data files then unpredictable problems arise. The compaction is only ever done when all users are off the system and one file at a time. Having done a compaction this week I found that one of the tables appeared corrupt when I browsed it via the program file (the table comes from one of the files which contains other tables working OK after the compaction). The data was garbled and what could be recognised was not in the right place - appears to be moved a couple of columns out of place. There were some fields which reported errors also. However when I browse the table in its native file it is perfectly OK. I can solve the problem by re-running the Linked Table Manager in the program file but that is hard work for 50 tables! This has happened previously when I compacted and I would be better understanding the problem than just fixing it! Can anyone help please?

View 3 Replies View Related

SELECT Clause With LAST Function Causing Problems

Jul 19, 2005

Hello all,


I have the following data, that was queried and sorted to columns PROBLEM_ID and then by STATUSDATE (ascending):

STATUS_ID STATUSDATE PROBLEM_ID
--------- ---------- ----------
10________12/04/2005___1234
40________15/05/2005___1234
10________11/11/2004___1235
50________15/12/2004___1235
70________20/01/2005___1235

I now want another query which returns the row which is always the latest STATUSDATE. This is what I have done so far:

SELECT qryFirst.PROBLEM_ID, Last(qryFirst.STATUS_ID) AS LAST_STATUS
FROM qryFirst
GROUP BY qryFirst.PROBLEM_ID;

However, when I want to add qryFirst.STATUSDATE to the SELECT clause, I get an error „You tried to execute a query that does not include the specified expression <name> as part of an aggregate function. (Error 3122)“

I need to see what the STATUSDATE is for each of the records returned in the second query. How do I do this? Please!!!!

Kind Regards,

Jean

View 7 Replies View Related

Dashes Are Causing Problems Retrieving Data

Aug 2, 2006

I have a database with a series of fields, all set to a String datatype, that I want to be able to fill and then use with MS Word as a mail merge data source. This function lets you query a MS Access db and use the results to fill in predefined spots attached to the various data values in the table. This is great for my needs however a large percentage of times that I have a dash in the value being queried it does not return any results. For example, 01-01 would return no entry found even though I can clearly see it in the database, however it would work fine if I queried for 0101 or any other value in the given field.

Basically I'm trying to figure out why dashes would cause problems. They are obviously fine for being stored in the access database and don't cause any troubles until they are queried for, also retrieving data containing dashes is fine so long as that value is not the one being queried for.

I basically can't avoid the dashes in the data for this setup and as such hopefully can figure out why this happens and how to get around it. Thanks for any help offered.

View 1 Replies View Related

Referential Integrity Causing Problems On Only 1 Table???

Jun 16, 2005

My db is an inventory of printers in use at our company. It is to tell us where they are, and what maintenance is done on them over time.

I have the following tables:


tblIP*
tblLocation*
tblMaintenance
tblMaintenanceType*
tblMake*
tblModel*
tblOffice*
tblPageCount
tblPrinter

The ones with stars are "type" tables. All possible IP's are in the tblIP, models in tblModel, office's in tblOffice etc.

Maintenance types are just like "fuser replacement", "toner replacement", "turned on computer" (IT joke)

anyway, On my main form. If I open the form and click the button I made to go to the previous record or next, I am fine.

If I choose an office, or start a record, I get a message that I have to have a record for IP chosen, that it can't leave this new record until it has an IP because of referential integrity.

If I choose an IP and nothing else, I can leave the new record. If I don't choose IP, but choose everything else, I cannot leave the record. AHHH!!!

The thing is, all my combos on the main form are (as explained above) FK's to lookup tables, and all set up the same: all with referential integrity, 1 - many, cascade updates and deletes.

This 1 table is the only one acting this way.

I am including a print screen of my form, as a visual sometimes helps.

If anyone can help me to fix this, I would really appreciate it. I have never had this problem before.

Thanks.

http://www.geocities.com/misscrf/printerentryform.jpg

View 6 Replies View Related

Multiple Subform Causing SLOW Loading

Oct 25, 2005

Hey firstly im at the end of the project ive spent months on and thats a MIS datase software. with all the bits and pieces and expert advise ive managed to learn a whole lot of things through this forum.

This is the problem i am having though;

i have a form that has two subforms embedded and since i have to use link tables because i placed the database file over a network somehow the loading seems to take forever, "it actually makes access inactive for about 50 seconds"

i would like to prevent the subforms from loading with the main form until after the main form is up and then i just click a button that makes both of them "appear" and load.

Can u advise. Much thanks.

:o

View 1 Replies View Related

Queries :: 3-way Relationship Causing Duplicate Entries

Dec 4, 2013

I know my way around Access reasonably well but am by no means an expert. I have created a system that I use in my business for hardware/software requests, and was told to do it in Access. I did ask that we do it on SQL Server with a Web Front End, but we are where we are.

Now, I have been on a SQL query training course so I know the basics, but am a bit confused on this one since Access has been added to the mix.To make matters more frightening, this is Access 2003!

My tables are as follows:

[T_Request]
AT Reference (primary key, autonumber)
Forename
Surname
UserID, etc etc

[T_Hardwarelist]
ID (primary key, autonumber)
Make
Model
Description

[T_UserHardware]
AT Reference
ID

[Request] is inner joined to [UserHardware] on the AT Reference column.
[UserHardware] is inner joined to [Hardwarelist] on the ID column.

The select query I have is basic and does just what it says on the tin; it shows who has what hardware.The query:

Code:
SELECT T_UserHardware.[AT Reference], T_UserHardware.ID, T_HardwareList.Make, T_HardwareList.Model, T_HardwareList.Type, T_HardwareList.Description
FROM (T_Requests INNER JOIN T_UserHardware ON T_Requests.[AT Reference] = T_UserHardware.[AT Reference]) INNER JOIN T_HardwareList ON T_UserHardware.ID = T_HardwareList.ID
WHERE (((T_UserHardware.[AT Reference])=[Forms]![F_Request]![AT Reference]));

However, when it comes to adding NEW hardware to the requestI have a form called F_Request.I have a sub form called SF_Hardware.The SF_ Hardware subform runs the aforementioned query, and shows what hardware is assigned to the parent request.If I add new hardware via a dropdown on the form, it adds it in to [T_UserHardware], but it also adds another value on the [T_Hardwarelist] table. E.g. if I add a "HP Compaq 8200 Elite" (which is stored in [T_Hardwarelist]) it adds it to the [T_UserHardware] table correctly, but creates a second (third, fourth, fifth) entry on the [T_Hardwarelist] table for the same kit.

I think its confusing because of using a select query and might have to run a 2nd query on save or something like that, I had a working version before that had the make, model etc in both tables and didn't have a 3-way relationship. It'd be nice to have the request table with the high level info, a hardwarelist table with our catalog of kit, and a userhardware table just containing the ID and Reference for the hardware/request rather than duplicating the information.

View 2 Replies View Related

Modules & VBA :: Assigning Value To Variable Causing Error

Jul 19, 2013

Is the following possible? If so - how?

I have a series of several hundred variables being assigned values.

If the value assigned to the variable results in an error, I would like to assign a default value to the variable which caused the error.

How do I reference the variable, or line (or any info I can work with), which caused the error?

View 2 Replies View Related







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