Modules & VBA :: Using String To Update Records - Quotes And Apostrophes In SQL Statements

Dec 4, 2014

I'm having problems with quotation marks in a sql statement. The string is an array separated by a semicolon.

120/80;70;5'6";125

this string represents patient vitals. I'm using the string to update a record. But I get hung up with the quotation mark.

I've tried: 120/80;70;5''6'"';125 which is a enclosing the quotation mark with apostrophies, but this does not seem to work. The sql still gets hung up. My sql statment looks something like:

original string: 120/80;70;5'6";125

strPreOpVits = "120/80;70;5''6'"';125"

mysql = "UPDATE mytable SET PreOpVits = '" & strPreOpVits & "' " & _
"WHERE nID = " & myRecID

docmd.runsql mysql

I've narrowed it down to the quotation marks and I'm unsure how to handle these. I get a runtime 3075 - Syntax Error.

Here is the code that I use to convert the original string

Public Function FixQuotesInSql(strToFix As String)
Dim lgth, y As Long
Dim strTemp, char2Add As Variant
'This routine fixes the use of apostrophe and quotation marks in an SQL sequence
'If the apostrophe is at the beginning or end of the string it replaces with 3 x "'" or "'''"
'If in the middle of the string then replaces with 2 x "'" or "''"

[Code] ....

View Replies


ADVERTISEMENT

Modules & VBA :: How To Handle String Values Containing Apostrophes Or Quotes

Sep 2, 2014

My db contains an unlinked form that is used to append records to 1-3 separate tables (tests to see if master records exists, appends if needed, moves on to child records). One of the fields is a text field meant for notes. The VBA errors out whenever this text contains apostrophes or quotes.

Is there a simple way to recall the string field with quotes and apostrophes intact and append it, or will I have to validate and remove them from the string?

View 3 Replies View Related

Quotes AND Apostrophes In Combo Box -how?

Jul 25, 2005

Hello,

I have a combo box on a form that simply selects a record from a 2-table query. My problem is that the data is Book Titles, which can contain both quotes and apostrophes, sometimes in the same title. other than eliminating these characters from the records, how do I make the simple vba code for the box work for either quotes or apostrophes in a record? The box works fine as long as the record does not contain these characters. (I'm a big vba rookie by the way, and this code was created by the box wizard.)
Using Access 2003,
Here is the code for the box:

Private Sub cboSelectBook_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[BookTitle] = '" & Me![cboSelectBook] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

TIA for any suggestions!
LMS

View 6 Replies View Related

Using Quotes In A String

Jun 14, 2006

Is there a way to generate a string for a text field that has Quotes in it.

I want to generate a string for a text field that has the following text in it.

The "ShankServer" has passed the test.

I need the Quotes (") to be in the text and of course the following will not work.

Me.GeneratedCode = "The "ShankServer" has passed the test."

View 3 Replies View Related

Escape Double Quotes In A String??

Jun 25, 2007

How do you guys escape the double quotes in the string..

Code:sRandomNumber = "1234"sCmdLine = "-RandomNumber="" & sRandomNumber & """

I tried this but this doesn't work...

sCmdLine = "-RandomNumber=""" & sRandomNumber & """"


I tried another method which doesn't work either...

sCmdLine = "-RandomNumber=" & chr(34) & sRandomNumber & chr(34).

What I got instead is this..

--snip--
-RandomNumber=""1234""
--snip--

Thanks...

View 5 Replies View Related

Quoting Double Quotes In A Select String

Oct 24, 2004

Could someone tell me if I need to break this select statement down? I'm running into problems with the DMax statement since it requires double quotes around it's arguments. When the parser hits the first argument, it closes the string like it's supposed to, but not the way I want it to.

In essence, the query returns 4 fields: unique ID, week number, computed score (TotSum), and the computed handicap (which is half the difference between your score and the high scorer):

Quote: strSQL = "SELECT tblRoster.HEDR, tblScores.WeekNo, " & _
"[A1T1]+[A1T2]+[A1T3]+[A2T1]+[A2T2]+[A2T3]+[A3T1]+[A3T2]+[A3T3] AS TotSum, " & _
"Round(((DMax("[TotSum]", "[qryHandicap]") - [TotSum]) / 2) + 0.1) AS Handicap " & _
"FROM tblRoster LEFT JOIN tblScores ON tblRoster.HEDR = tblScores.HEDR " & _
"WHERE (((tblScores.WeekNo) = " & inpWeekNum & ") And (TotSum > 0)) " & _
"ORDER BY TotSum DESC;"


What would the proper syntax be and/or is there a better way to obtain this information. After acquired, it is being salted away in a table which is recomputed after each competition.

Thanks for the input.

-Brian.

p.s. I know storing computed fields is a big no-no, but if you do not compete in a given week, the handicap from the last time you participated is used. This table will store the participants handicap as well as the last competition they were in. It seemed easier this way.

View 3 Replies View Related

Queries :: Update And Insert Records With SQL Statements Using Access 2010

Jul 10, 2014

I am trying to update and insert records with SQL statements. Below my code:

Select Case FirstGRV
Case "Y"
sql = "UPDATE Tbl_SellingPrices " & _
"SET SellingPrice = " & Me!Text2 & ", SellingPriceDateFrom = date(), SellingPriceDateTo = #" & Me!Text3 & "#" & _
"WHERE SellingPriceStockCode = Forms!Frm_GRV!GRVStockCode and SellingPriceDateFrom =#01-01-1900#;"

[Code] ....

My problem is I need to know if the execution of the SQL statement was successful or not. I use the RecordsAffected method, but it always returns 0, no matter what.

View 14 Replies View Related

Modules & VBA :: SQL String - Update Query Using A Variable Value

Jul 22, 2013

I am currently trying to create an update query (building a SQL String in VBA for a command button click event) to update a variable's value into a table.

Basically, there are 2 tables, displayed in 2 sub froms within the same main form. (OldTable and NewTable for arguments sake)

The basic method I want to implement is that a user highlights a record in the subform of "NewTable". (This value is stored as a variable "NewJPNUM" This value is then to be inserted into the highlighted row (or rows) of table OldTable on command button click.

So the basic idea is a user highlights a row in one table and this value is stored as a variable "NewJPNUM" . The user then highlights a row or rows in "OldTable" and the value from variable "NewJPNUM" is then written to field "NewJPNUM" in "NewTable" on command button click.

I am not experienced with Access but have decent experience in Excel / VBA so not really sure of best practice methods etc.

View 3 Replies View Related

Modules & VBA :: Match Partial Text String And Update Record

Jun 13, 2013

I am provided a spreadsheet that contains multiple rows of similar data; each row/record represents a different stage in the process of financial transactions (requisition, purchase order, & voucher payment). Each financial transaction has these three records, with the amounts in one of three columns (pre-encumbrance, encumbrance, and expense), depending on the process.

What I am really after is the fuller, more detailed description that is apparently only available for the two records I don't want to import into the database (which is tracking only expenses and not the other two stages of the process). There is apparently no way to cross-reference these multiple rows due to the way the original database was designed (and we apparently have no control over this).

After importing the spreadsheet into Access, I would like to match the partial text string (truncated description) to the full description in another record, and update the record with the truncated description to the full description. To make mattes more complicated, I will also have to match values in the "pre-enc" or "enc" field with the "exp" field across these three records to make sure the correct descriptions are being matched because the truncated description will match multiple distinct records with the longer description.

TypeDescrPreEncEncExp
VOUJsmith-Instructor, 12/16/13$0.00$0.00$45.00
POJSmith-Instructor, 12/16/13, Course1, Parking($45.00)$0.00$0.00
REQJSmith-Instructor, 12/16/13, Course1, Parking$0.00$45.00$0.00
VOUJsmith-Instructor, 12/16/13$0.00$0.00$221.13
POJSmith-Instructor, 12/16/13, Course1, Lodging($221.13)$0.00$0.00
REQJSmith-Instructor, 12/16/13, Course1, Lodging$0.00$221.13$0.00

View 5 Replies View Related

Modules & VBA :: MS Access 2010 String Records Of Two Tables

Feb 14, 2014

I have two tables linked via Project ID as shown in the attached file. I need Module to concatenate Project sub types against Project Types.

View 3 Replies View Related

Modules & VBA :: Database With Records - Search For Similar String

May 20, 2014

I am trying to write some code to search for similar strings. I am creating a database with records that all contain street addresses. These addresses may have more than one record attached to it, and we would like for folders to be created containing the records with similar street addresses. Problem is, all the existing records are from an excel spreadsheet that did not contain any data validation, so there are several instances of:

123 Street
123 st
123 street job 1
123 st job 2
etc....

So I am trying to write code to prevent this from happening in the future, by searching the database for a similar street address and asking the user if this is the address they are trying to enter. I have been trying to do this with the DLookUp function, as such:

Private Sub ProjectName_AfterUpdate()
Dim stLink, pName As String
pName = Me.ProjectName
stLink = DLookup("[ProjectName]", "tblMaster", "[ProjectName] LIKE '" & pName & "%'")
If IsNull(stLink) Or stLink = "" Then

[Code] ....

I have worded the stLink line different ways, and have used (*) instead of (%) but nothing is working. The CODE is working, as in no errors, but it is not finding a similar project that I know is present.

View 14 Replies View Related

Update Query. How Many Iif Statements Are Allowed?

Jan 30, 2008

Hi,

I am going to be creating a iif statement update qery, to update a column on dates, E.g. would be....

IIf([FinMonth] between 01/01/2008 and 31/01/2008,1)iif([FinMonth] between 01/02/2008 and 30/02/2008,2)iif(etc etc

2 questions??

1) Is 12 nested iif's statements are allowed within one IIF statement?
2) iS THERE AN EASIER WAY TO DO THIS??

Hope this explains enough.

Thanks

View 14 Replies View Related

Update Query With Multiple Part If Statements

Aug 13, 2014

I have a table where I have 5 columns, (BatteryL1, BatteryL2, BatteryR1, BatteryR2 and BatterySize).I want to update BatterySize, with a value if any one of the above listed columns contains a specific value using something like 'LIKE' in the query.

For example:
UPDATE Customers
SET BatterySize=13
WHERE BatteryL1 LIKE '%13%'

[code]...

View 3 Replies View Related

Queries :: Missing Operator Error In Multiple Update Statements

Jun 22, 2015

I'm trying to run about 300 update statements and keep getting a syntax error of missing operator... what could be wrong?

UPDATE Applicants set [NBCC ID] = '351174' where SSN = '136861387'
UPDATE Applicants set [NBCC ID] = '350960' where SSN = '138885740'
UPDATE Applicants set [NBCC ID] = '350817' where SSN = '140082154'
UPDATE Applicants set [NBCC ID] = '351013' where SSN = '145766662'

View 11 Replies View Related

Modules & VBA :: Separate Numbers And String From Alpha-numeric String

Jun 7, 2013

MS-Access VBA code to separate numbers and string from an alphanumeric string.

Example:

Source: 598790abcdef2T
Output Required: 598790

Source: 5789065432abcdefghijklT
Output Required: 5789065432

View 13 Replies View Related

Modules & VBA :: Filter Records - Adding Unbound Date Listbox To Filter String

Feb 10, 2014

I'm trying to hash two scripts I've found into 1 functioning filter, however I'm still relatively new to vba and can't figure out how to get this working.

I'm trying to use Allen Browne's Search Criteria:

with another snippete of code I found here:

Code:
'Purpose: This module illustrates how to create a search form, _
where the user can enter as many or few criteria as they wish, _
and results are shown one per line.

[Code]....

It's the date part I'm having trouble with, the rest of the search criteria work fine without the date, but I can't get it working when I try to modify and merge the date sections of each code.

Also I'm using a listbox for the "Yesterday";"Last 4 days";"Last 9 days" and not a combo box.

View 2 Replies View Related

Modules & VBA :: Update Or Add Records?

Oct 16, 2014

I have a table with about 1,2million records. I get an Excel list of about 35000 weekly, using which the table has to be updated: the records, that exist get fields updated, the ones that are new have to be added.

What is the fastest way to do this?

I'm trying with this code, but it's awfully slow, even if I read the update ranges into memory:

Code:
Set cn = CurrentProject.Connection
Set Rs = New ADODB.Recordset
Rs.Open "Select * from tbl_TTextract", cn, adOpenDynamic, adLockOptimistic
i = 2
Do While i < lr_2 + 1 'update
With Rs

[code]....

View 14 Replies View Related

Modules & VBA :: Using If And Case Statements

Dec 16, 2013

Basically I want to check if the Reporting Month already exists in the Months Table. If it exists it should ask the User wheter to overwrite or not. If the User clicks on OK it should delete one record from Months Table if the User clicks no, nothing should happen.However it doesn't delete the record, when I click on OK.

Code:

Public Sub IMPORT_Click()
Dim filelocation As Variant
Dim f As Object
Dim Message As String, Title As String, Default As String
Dim sql As String
Dim MsgReply As Integer

[code]....

View 1 Replies View Related

Modules & VBA :: Update Every Records Using Queries

Dec 27, 2013

I am new to MS Access and using MS Access 2013.I just added 50 new fields into a table. I need to update these new fields on every record.The table layout is as followed:

Table1
-Company Id
-Question1
-Question2
-Question50

[code]....

View 6 Replies View Related

Modules & VBA :: Update Selected Records

Mar 5, 2015

I have a datasheet subform where i need to select some records by clicking a check box and update a certain field/s of only those selected records.

View 1 Replies View Related

Modules & VBA :: SQL String - Append Records From Table Into Another Table

Mar 21, 2014

I have a form with a listbox that displays the name of a table. Once the listbox item is selected, the table name is set to a variable called myFile. I want append the records from the table (myFile) into another table.

View 1 Replies View Related

Modules & VBA :: Viewing Output Of SQL Statements

Feb 27, 2015

The following SQL statements run with no errors, but I can't see the output of the SQL statements. What is wrong with my "Debug.Print" or "rs" statement ? I would like to see the results. The SQL statements works when I save them to a query.

Dim db As DAO.Database
Dim rs As DAO.Recordset
Rem Dim intResult As Integer
Dim strSQL As String
Set db = CurrentDb

[Code] ....

View 4 Replies View Related

Modules & VBA :: Using Parameterized Values In SQL Statements

Oct 15, 2013

I've seen a common solution is to double up the apostrophe, replacing ' with " to avoid the special character however i also hear of another solution using "parameters".I tried have a look around on the internet and got confused so I thought maybe it would be better to ask here.

I just want to change my INSERT INTO and UPDATE commands to be able to use this (to prevent a potential sql injection) also i think its important to know im using DOA to code? (not sure if its important) either way.

View 3 Replies View Related

Modules & VBA :: Multiple If Statements Into One Procedure

Jun 26, 2013

I'm trying to put multiple IF statements into one procedure like the below:

Dim Answer As Integer
Answer = MsgBox("Have You Selected The Correct Outcome?", vbCritical + vbYesNo, "Continue Request?")
If Answer = vbYes Then 'Works fine here
'The bit I can't get right

[Code] .....

View 2 Replies View Related

Modules & VBA :: Update Records In Subform On Click

Aug 13, 2014

I have a form that contains a subform. I want to make a button that on click updates all the records listed in the subform. This is the best I came up with.

Dim rs As DAO.Recordset
Set rs = Me.SubList_for_Billing_Center_Form.Form.RecordsetC lone
With rs
.MoveFirst
Do While Not .EOF
.Edit
UPDATE Billing SET Billing.Billing_Declined = True, Billing.Billing_Declined_Date = Date()

[Code] ....

View 1 Replies View Related

Modules & VBA :: Update Multiple Records With Value From Inputbox?

Sep 11, 2014

Instead of using an update query, so my Audit Trail will continue to update correctly, I'd like to use an input box and run a function that performs much like an update query.

My problem is, only one out of 4 records updates correctly.

Code:
Me.txtTranTo = InputBox("Enter Location Transferring To:", "Location Transferring To", "")
Me.txtTranFrom.Value = Me.Location 'Old location
Me.Location.Value = Me.txtTranTo 'New location

The txtTranTo and txtTranFrom are unbound text boxes.

EDIT: Forgot to mention that this is in a continuous form.

View 1 Replies View Related







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