Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / April 2006

Tip: Looking for answers? Try searching our database.

INSERT INTO problems

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Markus - 11 Apr 2006 13:26 GMT
Hallo

I am having problems with the follwoing INSER INTO statment it comes up with
a (Enter Parameter Value) and i dont know why

This is the code

Dim strT As String
Dim strRA As String

strT = "XAAA" ' the strT value will change when opening the form but for
testing i left it as a fixed value

strRA = (strT & "A")  
DoCmd.RunSQL "INSERT INTO RACF_Table ( [RACF-ID] )  Values (" & strRA & ");"

This code runs when clicking on the add button

I hope some one can help
Duncan Bachen - 11 Apr 2006 13:46 GMT
> Hallo
>
[quoted text clipped - 15 lines]
>
> I hope some one can help

Since the value you are inserting is a string, you need to enclose it in
single quotes.

DoCmd.RunSQL "INSERT INTO RACF_Table ( [RACF-ID] )  Values ('" & strRA &
"');"

Signature

-D
Duncan Bachen
Director of I.T., Ole Hansen and Sons, Inc.

TC - 11 Apr 2006 13:47 GMT
Change this:

  DoCmd.RunSQL "INSERT INTO RACF_Table ( [RACF-ID] )  Values (" &
strRA & ");"

to this:

  dim sql as string
  sql = "INSERT INTO RACF_Table ( [RACF-ID] )  Values (""" & strRA &
""")"
  msgbox sql
  DoCmd.RunSQL  sql

I've fixed the quote-marks in your sql statement. I suggest you copy &
paste that line. Do not type it manually, or you might mess it up!

You should normally build sql statements into a string variable, as I
have shown above, so you can print the content using msgbox or
debug.print, when necessary to help with debugging. I've shown you that
above. You'll want to comment-out the msgbox statement when you're sure
the sql is correct. But keep using the string variable. The "wasted"
overhead in using a variable, when it is not really required, is
infinitesimal.

HTH,
TC (MVP Access)
http://tc2.atspace.com
Markus - 11 Apr 2006 14:15 GMT
Thank you TC and Duncan

"Markus" schrieb:

> Hallo
>
[quoted text clipped - 15 lines]
>
> I hope some one can help
Brian Wilson - 11 Apr 2006 14:24 GMT
> Thank you TC and Duncan

You need to be careful if the value itself might contain speech marks - if
so they need to be douled up.  As this sort of operation is so common, you
could create a bit of code to do any doubling up and surround the string in
quotes.  So you just need to write:

strValue=AddQuotes(strValue,DoubleQuote)

This function is my own - but I think it makes the code look more readable
than any other I have seen.

' ****** Code Starts ********
Option Compare Database
Option Explicit

Public Enum QuoteTypeEnum
   NoQuote
   SingleQuote
   DoubleQuote
End Enum

Public Function AddQuotes(strValue, Q As QuoteTypeEnum) As String

   Dim strReturn As String

   Select Case Q

   Case QuoteTypeEnum.SingleQuote
   strReturn = Replace(strValue, "'", "''")
   strReturn = "'" & strReturn & "'"

   Case QuoteTypeEnum.DoubleQuote
   strReturn = Replace(strValue, """", """""")
   strReturn = """" & strReturn & """"

   Case Else
   strReturn = strValue

   End Select

   AddQuotes = strReturn

End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.