Results 1 to 5 of 5
  1. #1
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451

    variable with "" in SQL


    i trying to save some log in information as a user logs in and am trying to save his currentproject.baseconnectionstring as part of it. my problem is that in that string is "" and i am having a hard time getting this into my insert SQL. has anyone done this or have any ideals?
    the variable db is

    Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=S:\shared\st\Share\Operations\Pro \Ho\HoMaster\HDesktop\Pro_Sup.accdb;Mode=Share Deny None;Extended Properties="";Jet OL

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,421
    have you tried just not including extended properties since you are not setting any anyway.

    and in what environment is this string being written - clearly not vba.

  3. #3
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    thanks for the reply Ajax, let me give a little back story. i whined on here many times about some of my issues, slow network and the one location that claims they are not using wifi but complain of crashes, i know they are using wifi. so with that what i am trying to put together is some information gathering in my FE's upon loading. i have been searching for any and all methods i can find and what i have come up with is a few currentproject and environ methods that i have set to variables to be saved each time they load. then i have a timer with a loop that will basicly time how long it takes to do a specific loop and save that time. my thought is to have this loop run a few times a day just so that i will be able to compare each locations network ability and if its better or worse at different times of day. i'm sure theres better prewritten codes out there but i was trying to work it out, i am open to suggestins though.

    Code:
    Option Compare Database
    Option Explicit
    ''''''''''''''''''''''''''''''''
    '  invisible start screen      '
    ''''''''''''''''''''''''''''''''
    Private Sub Form_Load()
        Private l As Integer
        Private id As String
        Private dtst As Date
        Private dted As Date
        Private dtdif As Integer
        Private curpath As String
        Private mach As String
        Private db As String
        Private cn As String
        Private ff As String
        Private itr As Boolean
        Private nm As String
        Private sz As String
        Private un As String
        Private logid As String
      
        CheckBackEnd 'relinks backend
    '    Me.Visible = False
        dtst = Now 'start timer
        id = fOSUserName
        idcheck (id) 'check if user is allowed, otherwise close
        l = DLookup("locationid", "operatort", "dsid='" & id & "'")
        curpath = CurrentProject.FullName
        db = CurrentProject.BaseConnectionString
        cn = CurrentProject.connection
        ff = CurrentProject.FileFormat
        itr = CurrentProject.IsTrusted
        nm = CurrentProject.Name
        sz = Environ("COMPUTERNAME")
        un = Environ("LOGONSERVER")
        Me.txtdsid = id
        Me.txtloc = l
        Me.txtpath = curpath
        Me.txtBaseConnectionString = db
        Me.txtFileFormat = ff
        Me.txtIsTrusted = itr
        Me.txtdbName = nm
        Me.txtcomputername = sz
        Me.txtlogonserver = un
        dted = Now 'end timer
        dtdif = DateDiff("s", dtst, dted) 'get time it took
        txttime = dtdif
        DoCmd.ShowToolbar "ribbon", acToolbarNo
        DoCmd.NavigateTo "acNavigationCategoryObjectType"
        DoCmd.RunCommand acCmdWindowHide
        DoCmd.ShowToolbar "ribbon", acToolbarYes
        DoCmd.SelectObject acTable, , True
        DoCmd.OpenForm "startf"
        
    
    End Sub
    this is my rough draft so far but like i said earlier i'm having trouble getting that string into my insert sql statement.
    Code:
    Private Sub log()
    Dim strlog As String
    strlog = ("INSERT INTO LogT(userid,location,fullname,baseconnectionstring,connection, " _
        & "fileformat,istrusted,dbname,computername,logonserver,starttime,endtime,SignalTime) " _
        & " VALUES ('" & id & "','" & l & "','" & curpath & "','" & db & "','" & cn & "', " _
        & " '" & ff & "','" & itr & "','" & nm & "','" & sz & "','" & un & "','" & dtst & "','" & dted & "','" & dtdif & "') ")
        CurrentDb.Execute (strlog)
        Debug.Print (strlog)
        logid = CurrentDb.OpenRecordset("select @@identity")(0)
        Debug.Print (logid)
    End Sub
    its the db variable that is giving me heck. I've tried singe, double, triple quotes, ch(34),ch(39) and combinations of both. i'm out of ideals, please help

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    Option1 - delete all that comes after the 4th ; since you probably don't need it anyway
    Option2 - use replace function to replace the "" with '' (two singles) as long as you're certain there will never be a value there, otherwise
    Option3 - find the string Properties=", replace the " with ' and test if the next character is a " and if so, replace it also. Otherwise find the next " and replace it.

    Far easier to just dump the last part. You cannot use chr(34) - it will only do the same as a literal " anyway. Your problem is that you have to concatenate what you need, or do Replace type functions. BTW, a form module is private, so declaring a form variable as Private is no different than a Dim statement, but the insinuation is that you would have something that you can't if you forgot the Private word (the possibility of a variable that is in scope beyond the form).
    Consider With blocks if you have a whack of form settings to make as it compartmentalizes things a bit, especially if indented:

    Code:
    With Me
      .txtdsid = id
      .txtloc = l
      .txtpath = curpath
      .txtBaseConnectionString = db
      .txtFileFormat = ff
      .txtIsTrusted = itr
      .txtdbName = nm
      .txtcomputername = sz
      .txtlogonserver = un
    End With
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    thanks micron, i'm thinking of going with either the option 1 or maybe do some more looking to see if there's another method that will get me as much data about the users environment that could be affecting the connections. and yes sorry but you caught me on the declares, this is basicly a test bench and I've been playing and moving things around. originally i started this in a module.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-11-2016, 02:05 PM
  2. Use a variable as the "Select * From" source!
    By gangel in forum Programming
    Replies: 4
    Last Post: 01-25-2016, 10:05 AM
  3. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  4. Replies: 3
    Last Post: 07-19-2014, 01:15 PM
  5. Update Query, Inserting Variable Number of "0"
    By bigchicagobob in forum Queries
    Replies: 4
    Last Post: 03-25-2014, 07:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums