Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2007, 06:48 PM
Authorized User
 
Join Date: Mar 2007
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default Syntax Error when updating data (setvalue)

Hi All,
I am getting a sytax error when i am setting the value from one table to another. The exact error is "Syntax error (missing operator) in query expression '[storename]='Kennedy's electrical cairnstest".
Now i know what is causing the error and that is the Apostrophe in the name Kennedy's as the code works well if the storename has no Apostrophe's. now i could modify data in the underlying table but this is a band aid and would not suit the overall function. My Code is as follows:
' if user has selected data from both list boxes open a hidden form and set value to unmatched store
    ' from existing store (StoreName)
    stDocName = "TblTelstraStaging subform"
    stLinkCriteria = "[StoreName]=" & "'" & Me![Text4] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , acHidden
    Forms![TblTelstraStaging subform]!StoreName = Me.Text6.Value
    DoCmd.close acForm, stDocName, acSaveYes

The error occurs on the set value line (2nd from the bottom)
Would anyone be able to help me with resolving this problem please?

Cheers
Darren

 
Old May 3rd, 2007, 01:15 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Since the subform is an object on the main form, you have to refer to Forms!MainFormName!SubFormName.SubFormControl.

I hate bang dot notation since it never seems to work correctly.

What is worse is that you are apparently opening a sub form, without a main form. Is the subform open by some other form? You can't open it if it is already open. Your best bet here would be to copy the sub form, rename it, then open it, and not the sub form. (and clean up your code as below)

So rename TblTelstraStaging subform to frmTelstraStagingHidden

Then

    Dim sText4, sText6 As String

    sText4 = Me.Text4
    sText6 = Me.Text6

    stDocName = "frmTelstraStagingHidden"
    stLinkCriteria = "[StoreName]='" & sText4 & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , acHidden
    Forms!frmTelstraStagingHidden.StoreName = sText6
    DoCmd.close acForm, stDocName, acSaveYes

Big problem here is that the hidden form never really gets open, and since there is latency, the value never comes back.

Single quotes and double quotes are never a good idea in a database. You could also substitute the ' with Chr(39) in the string like, "Kennedy" & Chr(39) & "s electrical cairnstest".

Did ANY of this help?



mmcdonal
 
Old May 3rd, 2007, 08:57 PM
Authorized User
 
Join Date: Mar 2007
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rob,

Thanks for your advice here, the form referred to as a subform is actually a main form and was just named as a sub form. I agree that " and ' and # etc should not be used in the datasets but the firm supplying this information won't budge. But i have taken your advice and cleaned up the code, (bear in mind this is a development version), using your advice i put that subform (tblTelstrastaging SubForm)onto the main form, to allow the sub form data to eliminate the hidden form problems, even with the ' existing the data updates with no problems at all.

Thanks for your Help

Cheers
Darren

 
Old May 3rd, 2007, 09:14 PM
Authorized User
 
Join Date: Mar 2007
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi macdonal,

Sorry don't know where the name Rob came from, i was in a conf call whilst replying to you.

thanks Again







Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 11: Error while updating user data pherank BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 March 16th, 2008 07:03 PM
syntax error?<%@ Import Namespace="System.Data" %> fjm9 ASP.NET 1.0 and 1.1 Basics 2 January 16th, 2007 11:51 AM
Syntax error? <%@ Import Namespace="System.Data" % fjm9 C# 1 January 16th, 2007 09:17 AM
SetValue doesn't work with DateTimePicker Infinity VB Components 0 January 4th, 2007 03:05 AM
Syntax error - C# data insert chuksted C# 1 April 21st, 2005 10:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.