how to convert query to vb code (1 Viewer)

isladogs

MVP / VIP
Local time
Today, 07:21
Joined
Jan 14, 2017
Messages
18,221
Code:
Code:
String (12," ") adds 12 spaces which indents the code by that amount.
On my system, tab width = 4 in the VBE options, so that's equivalent to vbTab & vbTab & vbTab

Similarly for String(8," ") & String (16," ")

Also very useful for quickly adding repeated characters like:
String(10,"=") gives ==========

Also note that I've used e.g.
Code:
String(16, " ") & "varitem = Replace(varitem,[B] ''''[/B], '')" & vbCrLf & _

This becomes
Code:
varitem = Replace(varitem, """", "")
after replacing single quotes with double quotes
which of course means remove the double quotes(") :)
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 07:21
Joined
Jul 9, 2003
Messages
16,282
Code:
String (12," ") adds 12 spaces which indents the code by that amount.

Thank you, it's not something I use, so I wasn't aware of its usefulness, if you know what I mean...
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 07:21
Joined
Jul 9, 2003
Messages
16,282
It's very nice to have these sorts of discussions because I need to learn some new tricks, otherwise I get stuck in my ways....
 

isladogs

MVP / VIP
Local time
Today, 07:21
Joined
Jan 14, 2017
Messages
18,221
I agree - I learn something new every day.
Trouble is I also forget at least three old things every day
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 07:21
Joined
Jul 9, 2003
Messages
16,282
I agree - I learn something new every day.
Trouble is I also forget at least three old things every day
Just say:- "I've forgotten more than you will ever know" it sounds better!

Sent from my SM-G925F using Tapatalk
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 07:21
Joined
Jul 9, 2003
Messages
16,282
...... I avoid the issue of building complicated SQL statements........
Example:-

Code:
'Example
'How to Format Text Data
strAgeRangeDesc = Chr(34) & strAgeRangeDesc & Chr(34)
'How to Format Date Data 1
strAgeRangeDate = Chr(35) & strAgeRangeDate & Chr(35)

UPDATE!!!!
I found this code by Ariel, basically a function for returning correctly formatted strings for SQL Statements. I thought it was excellent so I'm going to nick it!

So in future I will be using Ariel's code!

The actual thread is here:- https://www.access-programmers.co.uk/forums/showthread.php?p=1552061#post1552061

And this is an extract from the Threat:-

Nice Ariel!

Code:
Public Function SQLFIX(value As Variant) As String
'//// ATH Added - this is Ariel's code
    Select Case VarType(value)
    Case VbVarType.vbBoolean, VbVarType.vbByte, VbVarType.vbCurrency, _
        VbVarType.vbDouble, VbVarType.vbDecimal, VbVarType.vbInteger, _
        VbVarType.vbLong, VbVarType.vbSingle
        SQLFIX = value
    Case VbVarType.vbDate
        SQLFIX = "#" & Format(value, "mm/dd/yyyy") & "#"
    Case VbVarType.vbString
        SQLFIX = Chr(34) & value & Chr(34)
    Case VbVarType.vbNull
        SQLFIX = "Null"
    End Select
End Function
 
Last edited:

Users who are viewing this thread

Top Bottom