RedditPP Mascot

RedditPP

r/vba • … • u/Mythology

SQL Update Query to ADODB

So I have a loop that runs a set of update queries to an Access DB, the issue I seem to be having is that I build the SQL string based on the information input via a form (this is updating existing data, not new data, just to reiterate).

Anyway, the issue is that in the SQL string, some string variables are posting as blanks even though there IS information in the variable. The following is a sample of the concept I'm trying to get across.

>for i = lbound(arrayname) to ubound(arrayname)

> inputinfo = arrayname(i)

> sqlstr = "UPDATE [DBName] SET [DBName].Input = " & chr(34) & inputinfo & chr(34) & " WHERE [DBName].Field = " & FieldData

> conn.Execute(sqlstr)

>next i

Please understand this is a very crude example and barely representative of what I'm using. Assume FieldData is not a string and that the SQL string is being generated in a completely different module (with globals appropriately declared)

Now the issue is that the SQLstr keeps ending up like the following:

>UPDATE [DBName] SET [DBName].Input = "" WHERE [DBName].Field = FieldData

Is this because the data I'm looking for is coming from an array or because it's a string? I've found a really inefficient work around that I can use to fix it, which basically requires that portion of the SQL string to be built inside the module that's running the Execute, which may in the end be the only way this will work. If that's how it has to work though I'd appreciate more information as to why this works the way it does.

— 0