you shouldnt, queries are better.
but,
in the query, click the design,SQL button
copy sql
put in vb code
sql = "select * from table"
sql = "SELECT Format(Int((108120-[Value])/3600),"00") AS Total FROM tbl1 WHERE (((tbl1.Property)="100"));"
sql = "SELECT Format(Int((108120-[Value])/3600),'00') AS Total FROM tbl1 WHERE (((tbl1.Property)='100'));"
You can't use double quotes (") in SQL statements.
You either need to use single quotes (') or double double quotes ("")
So for example, your query should probably be
Code:sql = "SELECT Format(Int((108120-[Value])/3600),'00') AS Total FROM tbl1 WHERE (((tbl1.Property)='100'));"
I say probably as I haven't tested the section Format .... AS.
I would also recommend my SQL to VBA & back again utility as a way of learning how to do such conversions. Its easy & it works!
To convert query SQL to VBA, do the following:
a) Change your query from design view to SQL view. Copy it to the clipboard
b) Open the utility. Click the SQL tab and paste in the query SQL
c) Click the VBA tab and the converted VBA code will be shown.
You can then copy this into a VBA procedure
DoCmd.RunSQL " SELECT Format(Int((108120-[Value])/3600),""00"") AS Total " & _
" FROM tbl1 " & _
" WHERE (((tbl1.Property)=""100""));"
i did that and i got thisnow how can i show the result on the form in the unbound textbox ?Code:DoCmd.RunSQL " SELECT Format(Int((108120-[Value])/3600),""00"") AS Total " & _ " FROM tbl1 " & _ " WHERE (((tbl1.Property)=""100""));"
=DLookUp("Total","q1")
Private Sub Form_Load()
Me.Text0.Value = DLookup("Total", "q1")
End Sub
Private Sub Form_Load()
Me.Label0.Caption = DLookup("Total", "q1")
End Sub
sql = "SELECT Format(Int((108120-[Value])/3600),'00') AS Total FROM tbl1 WHERE (((tbl1.Property)='100'));"
=DLookup("City", "Customers", "CompanyName = ""MendipDataSystems""")
=DLookup("City", "Customers", "CompanyName = """ & [CompanyName] & """")
strSQL = strSELECT & strWHERE & strORDERBY & ";"
strSCase = String(12, " ") & "Dim strBase As String, dteDate As Date" & vbCrLf & vbCrLf & _
String(12, " ") & "|get common values" & vbCrLf & _
String(12, " ") & "strBase = result('base')" & vbCrLf & _
String(12, " ") & "dteDate = result('date')" & vbCrLf & vbCrLf & _
String(12, " ") & "|get string in array" & vbCrLf & _
String(12, " ") & "lngStart = InStr(1, strJSON, '''rates''') + 9" & vbCrLf & _
String(12, " ") & "lngEnd = InStr(lngStart, strJSON, '}')" & vbCrLf & _
String(12, " ") & "strTemp = Mid(strJSON, lngStart, lngEnd - lngStart)" & vbCrLf & _
String(12, " ") & "|parse string in array" & vbCrLf & _
String(12, " ") & "arrFieldsValues = Split(strTemp, ',')" & vbCrLf & vbCrLf & _
String(12, " ") & "For Each varitem In arrFieldsValues" & vbCrLf & _
String(16, " ") & "varitem = Replace(varitem, '''', '')" & vbCrLf & _
String(16, " ") & "arrTemp = Split(varitem, ':')" & vbCrLf & vbCrLf & _
String(16, " ") & ".AddNew" & vbCrLf & _
String(16, " ") & "!Currency = arrTemp(0)" & vbCrLf & _
String(16, " ") & "!Rate = arrTemp(1)" & vbCrLf & _
String(16, " ") & "!Base = strBase" & vbCrLf & _
String(16, " ") & "!Date = dteDate" & vbCrLf & _
String(16, " ") & ".Update" & vbCrLf & _
String(12, " ") & "Next"
'code for table 1 - tblCurrencyExchange
Set rst = db.OpenRecordset("tblCurrencyExchange", dbOpenDynaset, dbSeeChanges)
With rst
For Each result In JSON("result")
'-------------------------------------
Dim strBase As String, dteDate As Date
'get common values
strBase = result("base")
dteDate = result("date")
'get string in array
lngStart = InStr(1, strJSON, """rates""") + 9
lngEnd = InStr(lngStart, strJSON, "}")
strTemp = Mid(strJSON, lngStart, lngEnd - lngStart)
'parse string in array
arrFieldsValues = Split(strTemp, ",")
For Each varitem In arrFieldsValues
varitem = Replace(varitem, """", "")
arrTemp = Split(varitem, ":")
.AddNew
!Currency = arrTemp(0)
!Rate = arrTemp(1)
!Base = strBase
!Date = dteDate
.Update
Next
'-------------------------------------
Next
.Close
End With
String(16, " ") & "varitem = Replace(varitem,[B] ''''[/B], '')" & vbCrLf & _
varitem = Replace(varitem, """", "")
Just say:- "I've forgotten more than you will ever know" it sounds better!
Sent from my SM-G925F using Tapatalk