Using VBscript to access all values in JSON data - json

I have to do some vbscript that handles a json formatted output from a webserver. I am using an old vbscript code snippet I have found called "aspJSON" - I think it is from www.aspjson.com but that site is no longer available.
I have this JSON file:
{
"VAT":12678967.543233,
"buyInfo":{
"maximumBuyAmount":100,
"minimumBuyAmount":1,
},
"prices":[{
"unitPrice":12.50
"specialOfferPrice":8.75,
"period":{
"endDate":"\/Date(928142400000+0200)\/",
"startDate":"\/Date(928142400000+0200)\/",
},
}],
}
With the aspJSON code I can get some of the values from the data. Theese two will work fine:
Msgbox oJSON.data("VAT")
MsgBox oJSON.data("buyInfo").item("maximumBuyAmount")
But I cant seem to acces the values of prices:
[{"unitPrice":12.50}]
and period:
[{"period":{"endDate":"xxx"}}]
How can I access these values?
This is the aspJSON code:
'Februari 2014 - Version 1.17 by Gerrit van Kuipers
Class aspJSON
Public data
Private p_JSONstring
private aj_in_string, aj_in_escape, aj_i_tmp, aj_char_tmp, aj_s_tmp, aj_line_tmp, aj_line, aj_lines, aj_currentlevel, aj_currentkey, aj_currentvalue, aj_newlabel, aj_XmlHttp, aj_RegExp, aj_colonfound
Private Sub Class_Initialize()
Set data = Collection()
Set aj_RegExp = new regexp
aj_RegExp.Pattern = "\s{0,}(\S{1}[\s,\S]*\S{1})\s{0,}"
aj_RegExp.Global = False
aj_RegExp.IgnoreCase = True
aj_RegExp.Multiline = True
End Sub
Private Sub Class_Terminate()
Set data = Nothing
Set aj_RegExp = Nothing
End Sub
Public Sub loadJSON(inputsource)
inputsource = aj_MultilineTrim(inputsource)
If Len(inputsource) = 0 Then Err.Raise 1, "loadJSON Error", "No data to load."
select case Left(inputsource, 1)
case "{", "["
case else
Set aj_XmlHttp = CreateObject("Msxml2.ServerXMLHTTP")
aj_XmlHttp.open "GET", inputsource, False
aj_XmlHttp.setRequestHeader "Content-Type", "text/json"
aj_XmlHttp.setRequestHeader "CharSet", "UTF-8"
aj_XmlHttp.Send
inputsource = aj_XmlHttp.responseText
set aj_XmlHttp = Nothing
end select
p_JSONstring = CleanUpJSONstring(inputsource)
aj_lines = Split(p_JSONstring, Chr(13) & Chr(10))
Dim level(99)
aj_currentlevel = 1
Set level(aj_currentlevel) = data
For Each aj_line In aj_lines
aj_currentkey = ""
aj_currentvalue = ""
If Instr(aj_line, ":") > 0 Then
aj_in_string = False
aj_in_escape = False
aj_colonfound = False
For aj_i_tmp = 1 To Len(aj_line)
If aj_in_escape Then
aj_in_escape = False
Else
Select Case Mid(aj_line, aj_i_tmp, 1)
Case """"
aj_in_string = Not aj_in_string
Case ":"
If Not aj_in_escape And Not aj_in_string Then
aj_currentkey = Left(aj_line, aj_i_tmp - 1)
aj_currentvalue = Mid(aj_line, aj_i_tmp + 1)
aj_colonfound = True
Exit For
End If
Case "\"
aj_in_escape = True
End Select
End If
Next
if aj_colonfound then
aj_currentkey = aj_Strip(aj_JSONDecode(aj_currentkey), """")
If Not level(aj_currentlevel).exists(aj_currentkey) Then level(aj_currentlevel).Add aj_currentkey, ""
end if
End If
If right(aj_line,1) = "{" Or right(aj_line,1) = "[" Then
If Len(aj_currentkey) = 0 Then aj_currentkey = level(aj_currentlevel).Count
Set level(aj_currentlevel).Item(aj_currentkey) = Collection()
Set level(aj_currentlevel + 1) = level(aj_currentlevel).Item(aj_currentkey)
aj_currentlevel = aj_currentlevel + 1
aj_currentkey = ""
ElseIf right(aj_line,1) = "}" Or right(aj_line,1) = "]" or right(aj_line,2) = "}," Or right(aj_line,2) = "]," Then
aj_currentlevel = aj_currentlevel - 1
ElseIf Len(Trim(aj_line)) > 0 Then
if Len(aj_currentvalue) = 0 Then aj_currentvalue = aj_line
aj_currentvalue = getJSONValue(aj_currentvalue)
If Len(aj_currentkey) = 0 Then aj_currentkey = level(aj_currentlevel).Count
level(aj_currentlevel).Item(aj_currentkey) = aj_currentvalue
End If
Next
End Sub
Public Function Collection()
set Collection = CreateObject("Scripting.Dictionary")
End Function
Public Function AddToCollection(dictobj)
if TypeName(dictobj) <> "Dictionary" then Err.Raise 1, "AddToCollection Error", "Not a collection."
aj_newlabel = dictobj.Count
dictobj.Add aj_newlabel, Collection()
set AddToCollection = dictobj.item(aj_newlabel)
end function
Private Function CleanUpJSONstring(aj_originalstring)
aj_originalstring = Replace(aj_originalstring, Chr(13) & Chr(10), "")
aj_originalstring = Mid(aj_originalstring, 2, Len(aj_originalstring) - 2)
aj_in_string = False : aj_in_escape = False : aj_s_tmp = ""
For aj_i_tmp = 1 To Len(aj_originalstring)
aj_char_tmp = Mid(aj_originalstring, aj_i_tmp, 1)
If aj_in_escape Then
aj_in_escape = False
aj_s_tmp = aj_s_tmp & aj_char_tmp
Else
Select Case aj_char_tmp
Case "\" : aj_s_tmp = aj_s_tmp & aj_char_tmp : aj_in_escape = True
Case """" : aj_s_tmp = aj_s_tmp & aj_char_tmp : aj_in_string = Not aj_in_string
Case "{", "["
aj_s_tmp = aj_s_tmp & aj_char_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10))
Case "}", "]"
aj_s_tmp = aj_s_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10)) & aj_char_tmp
Case "," : aj_s_tmp = aj_s_tmp & aj_char_tmp & aj_InlineIf(aj_in_string, "", Chr(13) & Chr(10))
Case Else : aj_s_tmp = aj_s_tmp & aj_char_tmp
End Select
End If
Next
CleanUpJSONstring = ""
aj_s_tmp = split(aj_s_tmp, Chr(13) & Chr(10))
For Each aj_line_tmp In aj_s_tmp
aj_line_tmp = replace(replace(aj_line_tmp, chr(10), ""), chr(13), "")
CleanUpJSONstring = CleanUpJSONstring & aj_Trim(aj_line_tmp) & Chr(13) & Chr(10)
Next
End Function
Private Function getJSONValue(ByVal val)
val = Trim(val)
If Left(val,1) = ":" Then val = Mid(val, 2)
If Right(val,1) = "," Then val = Left(val, Len(val) - 1)
val = Trim(val)
Select Case val
Case "true" : getJSONValue = True
Case "false" : getJSONValue = False
Case "null" : getJSONValue = Null
Case Else
If (Instr(val, """") = 0) Then
If IsNumeric(val) Then
getJSONValue = CDbl(val)
Else
getJSONValue = val
End If
Else
If Left(val,1) = """" Then val = Mid(val, 2)
If Right(val,1) = """" Then val = Left(val, Len(val) - 1)
getJSONValue = aj_JSONDecode(Trim(val))
End If
End Select
End Function
Private JSONoutput_level
Public Function JSONoutput()
dim wrap_dicttype, aj_label
JSONoutput_level = 1
wrap_dicttype = "[]"
For Each aj_label In data
If Not aj_IsInt(aj_label) Then wrap_dicttype = "{}"
Next
JSONoutput = Left(wrap_dicttype, 1) & Chr(13) & Chr(10) & GetDict(data) & Right(wrap_dicttype, 1)
End Function
Private Function GetDict(objDict)
dim aj_item, aj_keyvals, aj_label, aj_dicttype
For Each aj_item In objDict
Select Case TypeName(objDict.Item(aj_item))
Case "Dictionary"
GetDict = GetDict & Space(JSONoutput_level * 4)
aj_dicttype = "[]"
For Each aj_label In objDict.Item(aj_item).Keys
If Not aj_IsInt(aj_label) Then aj_dicttype = "{}"
Next
If aj_IsInt(aj_item) Then
GetDict = GetDict & (Left(aj_dicttype,1) & Chr(13) & Chr(10))
Else
GetDict = GetDict & ("""" & aj_JSONEncode(aj_item) & """" & ": " & Left(aj_dicttype,1) & Chr(13) & Chr(10))
End If
JSONoutput_level = JSONoutput_level + 1
aj_keyvals = objDict.Keys
GetDict = GetDict & (GetSubDict(objDict.Item(aj_item)) & Space(JSONoutput_level * 4) & Right(aj_dicttype,1) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10))
Case Else
aj_keyvals = objDict.Keys
GetDict = GetDict & (Space(JSONoutput_level * 4) & aj_InlineIf(aj_IsInt(aj_item), "", """" & aj_JSONEncode(aj_item) & """: ") & WriteValue(objDict.Item(aj_item)) & aj_InlineIf(aj_item = aj_keyvals(objDict.Count - 1),"" , ",") & Chr(13) & Chr(10))
End Select
Next
End Function
Private Function aj_IsInt(val)
aj_IsInt = (TypeName(val) = "Integer" Or TypeName(val) = "Long")
End Function
Private Function GetSubDict(objSubDict)
GetSubDict = GetDict(objSubDict)
JSONoutput_level= JSONoutput_level -1
End Function
Private Function WriteValue(ByVal val)
Select Case TypeName(val)
Case "Double", "Integer", "Long": WriteValue = val
Case "Null" : WriteValue = "null"
Case "Boolean" : WriteValue = aj_InlineIf(val, "true", "false")
Case Else : WriteValue = """" & aj_JSONEncode(val) & """"
End Select
End Function
Private Function aj_JSONEncode(ByVal val)
val = Replace(val, "\", "\\")
val = Replace(val, """", "\""")
'val = Replace(val, "/", "\/")
val = Replace(val, Chr(8), "\b")
val = Replace(val, Chr(12), "\f")
val = Replace(val, Chr(10), "\n")
val = Replace(val, Chr(13), "\r")
val = Replace(val, Chr(9), "\t")
aj_JSONEncode = Trim(val)
End Function
Private Function aj_JSONDecode(ByVal val)
val = Replace(val, "\""", """")
val = Replace(val, "\\", "\")
val = Replace(val, "\/", "/")
val = Replace(val, "\b", Chr(8))
val = Replace(val, "\f", Chr(12))
val = Replace(val, "\n", Chr(10))
val = Replace(val, "\r", Chr(13))
val = Replace(val, "\t", Chr(9))
aj_JSONDecode = Trim(val)
End Function
Private Function aj_InlineIf(condition, returntrue, returnfalse)
If condition Then aj_InlineIf = returntrue Else aj_InlineIf = returnfalse
End Function
Private Function aj_Strip(ByVal val, stripper)
If Left(val, 1) = stripper Then val = Mid(val, 2)
If Right(val, 1) = stripper Then val = Left(val, Len(val) - 1)
aj_Strip = val
End Function
Private Function aj_MultilineTrim(TextData)
aj_MultilineTrim = aj_RegExp.Replace(TextData, "$1")
End Function
private function aj_Trim(val)
aj_Trim = Trim(val)
Do While Left(aj_Trim, 1) = Chr(9) : aj_Trim = Mid(aj_Trim, 2) : Loop
Do While Right(aj_Trim, 1) = Chr(9) : aj_Trim = Left(aj_Trim, Len(aj_Trim) - 1) : Loop
aj_Trim = Trim(aj_Trim)
end function
End Class

Unlike VAT and buyInfo, prices is a Collection which can contain multiple instances (notice the difference in the JSON structure, prices is encapsulated by square brackets). Whenever you deal with Collections a loop is required to iterate through the instances to get at their underlying properties.
I'd recommend a For Each loop, like below. #
Dim key, price
'Iterating a Scripting.Dictionary using For Each returns the key.
For Each key In oJSON.data("prices")
'Get the price instance by passing the key back into
'the Scripting.Dictionary.
Set price = oJSON.data("prices")(key)
MsgBox price.item("unitPrice")
MsgBox price.item("specialOfferPrice")
MsgBox price.item("period").item("endDate")
MsgBox price.item("period").item("startDate")
'Clear object before iterating the next instance.
Set price = Nothing
Next
# Code provided untested
Looking into this a bit more with some useful discussion with #omegastripes in the comments and looking through the aspJSON class, you should be able to access the Collection / Array items by ordinal, for example to get unitPrice you would use;
oJSON("prices")(0).Item("unitPrice")
With this in mind did a quick test script and here is the result.
Option Explicit
Dim prices: Set prices = CreateObject("Scripting.Dictionary")
Dim price, period
With prices
Set price = CreateObject("Scripting.Dictionary")
With price
Call .Add("unitPrice", 12.50)
Call .Add("specialOfferPrice", 8.75)
Set period = CreateObject("Scripting.Dictionary")
With period
Call .Add("endDate", "/Date(928142400000+0200)/")
End With
Call .Add("period", period)
End With
'Uses same method as the AddToCollection() in aspJSON to
'assign the ordinal position when adding the child Dictionary.
Call .Add(.Count, price)
End With
WScript.Echo prices(0).Item("unitPrice")
WScript.Echo prices(0).Item("period").Item("endDate")
Output:
12.5
/Date(928142400000+0200)/

Related

Error 2465 when trying to assign recordset value to control on subform in report

I am trying to fill 5 sub forms(Fr_Rep_x)(x=1 to 5) in a report(Report1) with recordset values(5 different pages) by invoking a public function 5 times.
The subforms and the public function are invoked in the report_activate event
I am getting the above error 2465: Application-defined or object-defined error
on the below line of the public function:
Reports("Report1").fr_name.Controls(Lbl_ON).Caption = rst("Order_Number")
Report Activate Event
Private Sub Report_Activate()
Dim i As Integer
For i = 1 To 5
DoCmd.OpenForm "Fr_Rep_" & i, , , , , acHidden
Call MORep(i, Forms!Fr_Main!NavSubform.Form!Lbox_Comp.Column(0), "00" & i & "0", Forms!Fr_Main!NavSubform.Form!Lbox_Comp.Column(3))
Next i
End Sub
Public Function
Public Sub MORep(Form_num As Integer, MO_ON As Long, MO_Op As String, Mat As String)
Dim fr_name As String
fr_name = "Fr_Rep_" & Form_num
var_order = MO_ON
var_op_n = MO_Op
var_mat = Mat
var_matdes = DLookup("Material_Description", "Tbl_MO_Rev_Control", "Material = '" & var_mat & "'")
var_matrev = DLookup("MO_Rev_No", "Tbl_MO_List_Archive", "Order_Number = " & var_order)
Dim rst As DAO.Recordset
Dim dbs As DAO.Database
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Tbl_MO_List_Archive", Type:=dbOpenDynaset)
rst.FindFirst "[Order_Number] = " & var_order '& "*'" & "AND MO_Rev_No ='" & var_mo_rev & ""
Dim str1
Reports("Report1").fr_name.Controls(Lbl_ON).Caption = rst("Order_Number")
Reports("Report1").fr_name.Form.Lbl_OQ.Caption = rst("Order_Qty")
Reports("Report1").fr_name.Form.Lbl_Batch.Caption = rst("Batch")
Reports("Report1").fr_name.Form.Lbl_MRP.Caption = rst("MRP_Controller")
Reports("Report1").fr_name.Form.Lbl_PC.Caption = rst("Profit_Center")
Reports("Report1").fr_name.Form.Lbl_PS.Caption = rst("Production_Scheduler")
Reports("Report1").fr_name.Form.Lbl_Mat.Caption = rst("Material")
Reports("Report1").fr_name.Form.Lbl_Pr_D.Caption = Format(rst("MO_Issue_Date"), "DD-MMM-YYYY")
Reports("Report1").fr_name.Form.Lbl_Pr_T.Caption = rst("MO_Issue_Time")
Set rst = Nothing
Forms(fr_name).Controls(Lbl_Mat_D).Caption = var_matdes
Forms(fr_name).Controls(Lbl_T_Pg).Caption = DLookup("Total_Pages", "Tbl_MO_Rev_Control", "MO_Rev_No = '" & var_matrev & "'")
Forms(fr_name).Controls(Lbl_SAP).Caption = "Form # " & DLookup("SAP_Form_no", "Tbl_MO_Rev_Control", "MO_Rev_No = '" & var_matrev & "'")
Set rst = dbs.OpenRecordset("Tbl_MO_Op_Archive", Type:=dbOpenDynaset)
rst.FindFirst "[Order_Number] = " & var_order '& "*'" & "AND MO_Rev_No ='" & var_mo_rev & ""
If var_op_n = "0010" Then
Forms(fr_name).Controls(Lbl_Ver_Drw_T).Visible = True
Forms(fr_name).Controls(Lbl_Ver_Drw_B).Visible = True
Forms(fr_name).Controls(Lbl_Ver_Drw_Sign).Visible = True
Forms(fr_name).Controls(Lbl_Ver_Drw_Dt).Visible = True
Forms(fr_name).Controls(Lbl_Pg).Caption = rst("10_Page_No")
Forms(fr_name).Controls(Lbl_Ver_Drw_Sign).Caption = rst("10_Verif_Drw_Rev_Stamp")
Forms(fr_name).Controls(Lbl_Ver_Drw_Dt).Caption = rst("10_Verif_Drw_Rev_Date_Stamp")
'hide stamp labels for op 0020 to 0050
Forms(fr_name).Controls(Lbl_FPV).Visible = False
Forms(fr_name).Controls(Lbl_Clk).Visible = False
Forms(fr_name).Controls(Lbl_Sign_Date).Visible = False
Forms(fr_name).Controls(Lbl_VS_Acc).Visible = False
Forms(fr_name).Controls(Lbl_VS_Rej).Visible = False
Forms(fr_name).Controls(Lbl_PC_NA).Visible = False
Forms(fr_name).Controls(Img_VS_Stamp).Visible = False
Forms(fr_name).Controls(Lbl_Stamp_Type).Visible = False
Forms(fr_name).Controls(Lbl_PC_Stamp).Visible = False
Forms(fr_name).Controls(Lbl_PC_Acc).Visible = False
Forms(fr_name).Controls(Lbl_PC_Rej).Visible = False
Forms(fr_name).Controls(Lbl_Rej).Visible = False
ElseIf var_op_n = "0020" Then
Forms(fr_name).Controls(Lbl_FPV).Visible = True
Forms(fr_name).Controls(Lbl_Clk).Visible = True
Forms(fr_name).Controls(Lbl_Sign_Date).Visible = True
Forms(fr_name).Controls(Lbl_VS_Acc).Visible = True
Forms(fr_name).Controls(Lbl_VS_Rej).Visible = True
Forms(fr_name).Controls(Lbl_PC_NA).Visible = True
Forms(fr_name).Controls(Lbl_PC_Acc).Visible = True
Forms(fr_name).Controls(Lbl_PC_Rej).Visible = True
Forms(fr_name).Controls(Lbl_Rej).Visible = True
Forms(fr_name).Controls(Lbl_Ver_Drw_T).Visible = False
Forms(fr_name).Controls(Lbl_Ver_Drw_B).Visible = False
Forms(fr_name).Controls(Lbl_Ver_Drw_Sign).Visible = False
Forms(fr_name).Controls(Lbl_Ver_Drw_Dt).Visible = False
Forms(fr_name).Controls(Lbl_Pg).Caption = rst("20_Page_No")
Forms(fr_name).Controls(Lbl_FPV).Caption = rst("20_First_Pc_Verif_Stamp")
Forms(fr_name).Controls(Lbl_Clk).Caption = rst("20_Clock_No_Stamp")
Forms(fr_name).Controls(Lbl_Sign_Date).Caption = rst("20_Date_Stamp")
Forms(fr_name).Controls(Lbl_VS_Acc).Caption = rst("20_Sample_Verif_Acc_Stamp")
Forms(fr_name).Controls(Lbl_VS_Rej).Caption = rst("20_Sample_Verif_Rej_Stamp")
Forms(fr_name).Controls(Lbl_PC_NA).Caption = rst("20_Verif_Stamp_Type") 'user stamp not stored in 0020 op, only NA comment
Forms(fr_name).Controls(Lbl_PC_Acc).Caption = rst("20_Pc_Comp_Acc_Stamp")
Forms(fr_name).Controls(Lbl_PC_Rej).Caption = rst("20_Pc_Comp_Rej_Stamp")
Forms(fr_name).Controls(Lbl_Rej).Caption = rst("20_Reject_No_Stamp")
ElseIf var_op_n = "0030" Then
Forms(fr_name).Controls(Img_VS_Stamp).Visible = False
Forms(fr_name).Controls(Lbl_Stamp_Type).Visible = False
Forms(fr_name).Controls(Lbl_PC_Stamp).Visible = False
Forms(fr_name).Controls(Lbl_Pg).Caption = rst("30_Page_No")
Forms(fr_name).Controls(Lbl_FPV).Caption = rst("30_First_Pc_Verif_Stamp")
Forms(fr_name).Controls(Lbl_Clk).Caption = rst("30_Clock_No_Stamp")
Forms(fr_name).Controls(Lbl_Sign_Date).Caption = rst("30_Date_Stamp")
Forms(fr_name).Controls(Lbl_VS_Acc).Caption = rst("30_Sample_Verif_Acc_Stamp")
Forms(fr_name).Controls(Lbl_VS_Rej).Caption = rst("30_Sample_Verif_Rej_Stamp")
Forms(fr_name).Controls(Lbl_PC_NA).Caption = rst("30_Verif_Stamp_Type") 'user stamp not stored in 0030 op, only NA comment
Forms(fr_name).Controls(Lbl_PC_Acc).Caption = rst("30_Pc_Comp_Acc_Stamp")
Forms(fr_name).Controls(Lbl_PC_Rej).Caption = rst("30_Pc_Comp_Rej_Stamp")
Forms(fr_name).Controls(Lbl_Rej).Caption = rst("30_Reject_No_Stamp")
ElseIf var_op_n = "0040" Then
Forms(fr_name).Controls(Lbl_Pg).Caption = rst("40_Page_No")
Forms(fr_name).Controls(Lbl_FPV).Caption = rst("40_First_Pc_Verif_Stamp")
Forms(fr_name).Controls(Lbl_Clk).Caption = rst("40_Clock_No_Stamp")
Forms(fr_name).Controls(Lbl_Sign_Date).Caption = rst("40_Date_Stamp")
Forms(fr_name).Controls(Lbl_VS_Acc).Caption = rst("40_Sample_Verif_Acc_Stamp")
Forms(fr_name).Controls(Lbl_VS_Rej).Caption = rst("40_Sample_Verif_Rej_Stamp")
Forms(fr_name).Controls(Lbl_PC_Stamp).Caption = rst("40_Verification_Stamp") 'user stamp IS stored in 0040 op
Forms(fr_name).Controls(Lbl_Stamp_Type).Caption = rst("40_Verif_Stamp_Type") 'user stamp IS stored in 0040 op
Forms(fr_name).Controls(Lbl_PC_Acc).Caption = rst("40_Pc_Comp_Acc_Stamp")
Forms(fr_name).Controls(Lbl_PC_Rej).Caption = rst("40_Pc_Comp_Rej_Stamp")
Forms(fr_name).Controls(Lbl_Rej).Caption = rst("40_Reject_No_Stamp")
ElseIf var_op_n = "0050" Then
Forms(fr_name).Controls(Img_VS_Stamp).Visible = False
Forms(fr_name).Controls(Lbl_Stamp_Type).Visible = False
Forms(fr_name).Controls(Lbl_PC_Stamp).Visible = False
Forms(fr_name).Controls(Lbl_Pg).Caption = rst("50_Page_No")
Forms(fr_name).Controls(Lbl_FPV).Caption = rst("50_First_Pc_Verif_Stamp")
Forms(fr_name).Controls(Lbl_Clk).Caption = rst("50_Clock_No_Stamp")
Forms(fr_name).Controls(Lbl_Sign_Date).Caption = rst("50_Date_Stamp")
Forms(fr_name).Controls(Lbl_VS_Acc).Caption = rst("50_Sample_Verif_Acc_Stamp")
Forms(fr_name).Controls(Lbl_VS_Rej).Caption = rst("50_Sample_Verif_Rej_Stamp")
Forms(fr_name).Controls(Lbl_PC_NA).Caption = rst("50_Verif_Stamp_Type") 'user stamp not stored in 0030 op, only NA comment
Forms(fr_name).Controls(Lbl_PC_Acc).Caption = rst("50_Pc_Comp_Acc_Stamp")
Forms(fr_name).Controls(Lbl_PC_Rej).Caption = rst("50_Pc_Comp_Rej_Stamp")
Forms(fr_name).Controls(Lbl_Rej).Caption = rst("50_Reject_No_Stamp")
End If
If Form_num = 5 Then
Set rst = Nothing
Set dbs = Nothing
End If
If var_op_n = "0020" Or var_op_n = "0050" Then
Forms(fr_name).Controls(Lbl_FPV).Top = 5250
Forms(fr_name).Controls(Lbl_Clk).Vertical = False
Forms(fr_name).Controls(Lbl_Clk).Top = 5250
Forms(fr_name).Controls(Lbl_Sign_Date).Top = 5250
Forms(fr_name).Controls(Lbl_VS_Acc).Top = 5250
Forms(fr_name).Controls(Lbl_VS_Rej).Top = 5250
Forms(fr_name).Controls(Lbl_PC_NA).Top = 5250
Forms(fr_name).Controls(Lbl_PC_Acc).Top = 5250
Forms(fr_name).Controls(Lbl_PC_Rej).Top = 5250
Forms(fr_name).Controls(Lbl_Rej).Top = 5250
Else
Forms(fr_name).Controls(Lbl_FPV).Top = 7250
Forms(fr_name).Controls(Lbl_Clk).Vertical = True
Forms(fr_name).Controls(Lbl_Clk).Top = 7250
Forms(fr_name).Controls(Lbl_Sign_Date).Top = 7250
Forms(fr_name).Controls(Lbl_VS_Acc).Top = 7250
Forms(fr_name).Controls(Lbl_VS_Rej).Top = 7250
Forms(fr_name).Controls(Lbl_PC_NA).Top = 7250
Forms(fr_name).Controls(Lbl_PC_Acc).Top = 7250
Forms(fr_name).Controls(Lbl_PC_Rej).Top = 7250
Forms(fr_name).Controls(Lbl_Rej).Top = 7250
End If
Call OpNum
Call MatNum
Call MatRev
'Forms(fr_name)(Lbox_Op_List).Requery
'Forms(fr_name).Controls(Lbox_Op).Requery
Forms(fr_name).Controls(Lbl_Op).Caption = DLookup("Operation_Description", "Tbl_Ops_Desc", "MO_Rev_No = '" & var_matrev & "' AND Oper_No ='" & var_op_n & "'")
End Sub
Report Structure and Code movement Getting stuck at step 6, All forms have same controls and control names
please advice, I guess the report subform control referencing is wrong?
As to your code, Lbl_ON has not been assigned a value here:
Reports("Report1").fr_name.Controls(Lbl_ON).Caption = rst("Order_Number")
To check, insert a debug line. Also, try specifying the Value property:
Debug.Print "Lbl_ON:", Lbl_ON
Reports("Report1").fr_name.Controls(Lbl_ON).Caption = rst("Order_Number").Value
If Lbl_ON can be Null, there is no control to access, thus:
If Not IsNull(Lbl_ON) then
Reports("Report1").fr_name.Controls(Lbl_ON).Caption = rst("Order_Number").Value
End If
That will, of course, not adjust anything, so you will wish to correct that Lbl_ON has no value.

Loading only HTML without any style and scripts

I have one VBA script, that find some data on web (csfd.cz) and put into Excel. But it is quite slow because it takes some time to load the website (in IE) and then extract data. My thought is how to make that IE only loads HTML and it doesn't load any graphics and functional things - only pure HTML. Is it somehow possible? Thanks for help...
here is my code:
Sub InputData()
Dim cursor As String
Dim i As Long
Dim ie As Object
Dim lastRow As Long
Dim releasesLength As Long
Dim releases As Object
Dim oneRelease As Object
Dim datumKino As String
Dim datumDVD As String
Dim origins As String
Dim year As Long
Dim time As Long
Dim name As String
Dim genreLong As String
Dim genre As String
'zapamatování kurzoru
cursor = ActiveCell.Address
'zjištění posledního řádku
With ActiveSheet
lastRow = .Cells(.Rows.Count, "L").End(xlUp).Row
End With
'první viditelná buňka
Range("L2").Select
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Height <> 0
ActiveCell.Offset(1, 0).Select
Loop
'inicializace
Set ie = CreateObject("InternetExplorer.Application")
'ZAČÁTEK SMYČKY--------------------------------------------------------------
For i = ActiveCell.Row To lastRow
Cells(i, 12).Select
'resetování proměných
releasesLength = vbNullLong
Set releases = Nothing
Set oneRelease = Nothing
datumKino = ""
datumDVD = ""
origins = ""
year = vbNullLong
time = vbNullLong
name = ""
genreLong = ""
genre = ""
'vyřazení
If (InStr(Cells(i, 12).Value, "csfd.cz") = 0 Or ActiveCell.Height = 0) Then
GoTo NextRow
End If
'otevření stránky
ie.Visible = False
ie.navigate Cells(i, 12).Value
Application.StatusBar = "Načítám údaje. Prosím počkejte..."
Do While ie.busy
Application.Wait DateAdd("s", 1, Now)
Loop
'úprava procent a datumů
Cells(i, 9).Value = ie.document.getElementById("rating").Children(0).innerText
releasesLength = ie.document.getElementById("releases").getElementsByClassName("content")(0).getElementsByTagName("table")(0).getElementsByTagName("tbody")(0).Children.Length
Set releases = ie.document.getElementById("releases").getElementsByClassName("content")(0).getElementsByTagName("table")(0).getElementsByTagName("tbody")(0).Children
For j = 0 To releasesLength - 1
Set oneRelease = releases(j)
If (oneRelease.getElementsByTagName("th")(0).getElementsByTagName("img")(0).getAttribute("title") = "Česko") Then
If (InStr(oneRelease.getElementsByTagName("th")(0).innerHTML, "V kinech")) Then
If (datumKino = "") Then
datumKino = Left(Replace(Replace(Replace(oneRelease.getElementsByTagName("td")(0).innerHTML, " ", ""), vbLf, ""), vbTab, ""), 10)
End If
ElseIf (InStr(oneRelease.getElementsByTagName("th")(0).innerHTML, "Na DVD")) Then
If (datumDVD = "") Then
datumDVD = Left(Replace(Replace(Replace(oneRelease.getElementsByTagName("td")(0).innerHTML, " ", ""), vbLf, ""), vbTab, ""), 10)
End If
ElseIf (InStr(oneRelease.getElementsByTagName("th")(0).innerHTML, "Na Blu-ray")) Then
If (datumDVD = "") Then
datumDVD = Left(Replace(Replace(Replace(oneRelease.getElementsByTagName("td")(0).innerHTML, " ", ""), vbLf, ""), vbTab, ""), 10)
End If
End If
Else
GoTo NextRelease
End If
NextRelease:
Next j
If (Len(datumKino) <> 0) Then
Cells(i, 1).Value = datumKino
End If
If (Len(datumDVD) <> 0) Then
Cells(i, 2).Value = datumDVD
End If
'1. první zápis do řádku
If (Cells(i, 4).Value = "") Then
year = ie.document.getElementsByClassName("origin")(0).getElementsByTagName("span")(0).innerHTML
Cells(i, 4).Value = year
origin = ie.document.getElementsByClassName("origin")(0).innerHTML
originSplit = Split(origin, ",")
time = Replace(originSplit(UBound(originSplit)), " min", "")
Cells(i, 10).Value = time
name = Replace(Replace(ie.document.getElementsByClassName("info")(0).getElementsByClassName("header")(0).getElementsByTagName("h1")(0).innerHTML, vbLf, ""), vbTab, "")
Cells(i, 3).Value = name
genreLong = ie.document.getElementsByClassName("genre")(0).innerHTML
genre = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(genreLong, " ", ""), "Akční", "Akč."), "Animovaný", "Anim."), "Dobrodružný", "Dobr."), "Dokumentární", "Dokument."), "Fantasy", "Fant."), "Historický", "Histor."), "Katastrofický", "Katastrof."), "Komedie", "Kom."), "Mysteriózní", "Myster."), "Rodinný", "Rod."), "Romantický", "Romant."), "Thriller", "Thril."), "Životopisný", "Životopis.")
Cells(i, 5).Value = genre
End If
NextRow:
Next i
'KONEC SMYČKY----------------------------------------------------------------
'Clean
ie.Quit
Set ie = Nothing
Set releases = Nothing
Set oneRelease = Nothing
Application.StatusBar = ""
Range(cursor).Select
End Sub

Classic ASP inserting variable value into Access DB

I am trying to insert a variable value into my access database, I am able to insert a value that's pre-set like
<td width="125" nowrap="nowrap" ><div align="right">Lead From </div></td>
<td><input name="lead" type="text" id="lead" value="" size="50" /></td>
as you can see we have a id of "lead" and I can insert that into the db fine like this:
MM_fieldsStr = "lead|value";
MM_columnsStr = "Lead|',none,''";
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
now I want to be able to do something like this:
Session("MM_JobNumber") = job_number
MM_fieldsStr = job_number & "|value"
MM_columnsStr = "Job_Num|',none,''"
when ever i try pass a variable through it returns null, ofc you cant see job number being set in the code i have supplied but it does 100% get set.
COUNTER RECORDER::
Dim countrec
Dim countrec_numRows
Set countrec = Server.CreateObject("ADODB.Recordset")
countrec.ActiveConnection = MM_JobConn_STRING
countrec.Source = "SELECT * FROM CounterTAB WHERE Counter_ID = 1"
countrec.CursorType = 0
countrec.CursorLocation = 2
countrec.LockType = 1
countrec.Open()
countrec_numRows = 0
FULL CODE BELOW::
If (CStr(Request("MM_insert")) = "form2") Then
Dim job_number
IF (Session("MM_JobNumber") <> "") OR (Session("MM_JobNumber") <> NULL)Then
job_number = Session("MM_JobNumber")
Else
Dim new_count_num
new_count_num = countrec.Fields.Item("Counter_NUM").Value+1
job_number = PadDigits(new_count_num, 4) + "-" + mid(DatePart("yyyy",now()),3,2)
Session("MM_JobNumber") = job_number
END IF
'UPDATE COUNTER
set counterupdate = Server.CreateObject("ADODB.Command")
counterupdate.ActiveConnection = MM_JobConn_STRING
counterupdate.CommandText = "UPDATE CounterTAB SET Counter_NUM = Counter_NUM + 1 WHERE Counter_ID = 1"
counterupdate.CommandType = 1
counterupdate.CommandTimeout = 0
counterupdate.Prepared = true
counterupdate.Execute()
MM_editConnection = MM_JobConn_STRING
MM_editTable = "Job_Details"
MM_editRedirectUrl = "view_jobs_new.asp?offset=-1"
MM_fieldsStr = job_number & "|value|hiddenDateRaised|value|hiddenYearRaised|value|hiddenNewRaisedBYID|value|hiddenRaisedBYID|value|hiddenFieldCompanyID|value|hiddenFieldContact1|value|Job_Ref_Name|value|checkbox3_1|value|checkbox3_15|value|checkbox3_4|value|checkbox3_2|value|checkbox3_16|value|checkbox3_5|value|checkbox3_3|value|checkbox3_6|value|checkbox3_7|value|checkbox3_22|value|checkbox3_8|value|checkbox3_9|value|checkbox3_23|value|checkbox3_10|value|checkbox3_20|value|checkbox3_11|value|checkbox3_17|value|checkbox3_12|value|checkbox3_21|value|checkbox3_13|value|checkbox3_18|value|checkbox3_24|value|checkbox3_14|value|checkbox3_19|value|checkbox3_25|value|checkbox3_26|value|DescriptText|value|sitename|value|siteAdd1|value|siteAdd2|value|siteAdd3|value|siteAdd4|value|siteAdd5|value|sitePostCode|value|lead|value"
MM_columnsStr = "Job_Num|',none,''|Job_Date|',none,''|Job_Year|none,none,NULL|New_Raised_By|none,none,NULL|Raised_By|none,none,NULL|Company|none,none,NULL|Contact|none,none,NULL|Job_Ref|',none,''|Scope_3_01_SiteDecom|none,-1,0|Scope_3_15_Spill|none,-1,0|Scope_3_04_TankClean|none,-1,0|Scope_3_02_SiteClosure|none,-1,0|Scope_3_16_EnviroAss|none,-1,0|Scope_3_05_OtherTankClean|none,-1,0|Scope_3_03_GroundRem|none,-1,0|Scope_3_06_TankLining|none,-1,0|Scope_3_07_TankPainting|none,-1,0|Scope_3_22_SaleFuel|none,-1,0|Scope_3_08_ShipTank|none,-1,0|Scope_3_09_VapourRec|none,-1,0|Scope_3_23_SaleRec|none,-1,0|Scope_3_10_Petroscope|none,-1,0|[Scope_3_20_IBC Testing]|none,-1,0|Scope_3_11_Vacutect|none,-1,0|Scope_3_17_FuelSys|none,-1,0|Scope_3_12_TankCalib|none,-1,0|Scope_3_21_FuelSampling|none,1,0|Scope_3_13_5stage|none,-1,0|Scope_3_18_Oftec|none,-1,0|Scope_3_24_SpillKit|none,-1,0|Scope_3_14_Rail|none,-1,0|Scope_3_19_TankerServices|none,-1,0|Scope_3_25_Training|none,-1,0|Scope_3_26_Other|none,-1,0|Job_Description|',none,'' | Site_Name|',none,''|Site_Add1|',none,''|Site_Add2|',none,''|Site_Add3|',none,''|Site_Add4|',none,''|Site_Add5|',none,''|Site_Postcode|',none,''|Lead_From|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
INSERT CODE::
' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues
Dim MM_dbValues
If (CStr(Request("MM_insert")) <> "") Then
'here goes counter update
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
Session("MM_JobNumber") = NULL
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
Split() deals with separators, not delimiters. So the trailing "|" in
MM_columnsStr = "Job_Num|',none,''|"
causes a spurious/empty element in the array. Evidence:
>> s = "Lead|',none,''"
>> a = Split(s, "|")
>> WScript.Echo UBound(a), a(UBound(a))
>>
1 ',none,''
>> s = "Job_Num|',none,''|"
>> a = Split(s, "|")
>> WScript.Echo UBound(a), a(UBound(a))
>>
2
On second thought:
This
>> job_number = "JN"
>> MM_fieldsStr = job_number & "|value"
>> WScript.Echo MM_fieldsStr
>>
JN|value
should prove, that string concatenation works in VBScript. If you get
|value
then job_number is empty before the & line. Perhaps you meant
job_number = Session("MM_JobNumber")
instead of
Session("MM_JobNumber") = job_number
Last thought:
This:
IF (Session("MM_JobNumber") <> "") OR (Session("MM_JobNumber") <> NULL)Then
job_number = Session("MM_JobNumber")
will set job_number only if is not empty or Null.
all that was needed was to pad the job_number string out with ' ' marks at the start and end, hope this helps anyone else trying to do something similar

i am trying to use the dirty option on my unbound form. how do i do this? below is all the code for the form. in access 2010 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
i am trying to use the dirty option but do not know where to start as it is a unbound form, how do i code it correctly?
i would like to use form.dirty if possible on the close event.
Private Sub cmd_saverecord_Click()
Call saverecord
End Sub
Private Sub Form_Load()
Dim sql As String, db As DAO.Database, rs As Recordset
Set db = CurrentDb
sql = "SELECT tbl_vr.*, tbl_customer.customer_name, tbl_customer.customer_number, tbl_customer.customer_d_number, tbl_customer.customer_email " _
& "FROM tbl_vr INNER JOIN tbl_customer ON tbl_vr.customer_id = tbl_customer.customer_id " _
& "WHERE tbl_vr.vr_id=" & get_current_vr_id()
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
With rs
txt_vr_id = .Fields("vr_id")
txt_vr_reference = .Fields("vr_reference")
txt_external_reference = .Fields("vr_external_reference")
txt_vr_project = .Fields("vr_project")
cbo_part_master_id = .Fields("part_master_id")
cbo_part_master_revised_id = .Fields("part_master_revised_id")
txt_vr_creation_date = .Fields("vr_creation_date")
txt_vr_anticipated_dispatch = .Fields("vr_anticipated_dispatch")
txt_vr_quote_to_customer = .Fields("vr_quote_to_customer")
txt_vr_quote_acceptance = .Fields("vr_quote_acceptance")
txt_vr_quote_rejection = .Fields("vr_quote_rejection")
txt_vr_received_at_mbda = .Fields("vr_received_at_mbda")
txt_vr_sent_to_repairer = .Fields("vr_sent_to_repairer")
txt_vr_received_from_repairer = .Fields("vr_received_from_repairer")
txt_vr_predicted_return_date = .Fields("vr_predicted_return_date")
txt_vr_actual_dispatch_date = .Fields("vr_actual_dispatch_date")
txt_vr_received_by_customer = .Fields("vr_received_by_customer")
txt_vr_serial_no = .Fields("vr_serial_no")
txt_customer_name = .Fields("customer_name")
txt_user_id = .Fields("user_id")
txt_customer_email = .Fields("customer_email")
txt_customer_number = .Fields("customer_number")
txt_customer_number_d = .Fields("customer_d_number")
cbo_part_master_id_AfterUpdate
cbo_part_master_revised_id_AfterUpdate
End With
Me.cbo_dates.RowSource = ""
sql = "SELECT tbl_roles.* " _
& "FROM tbl_roles INNER JOIN tbl_user ON tbl_roles.[Role ID] = tbl_user.role_id " _
& "WHERE tbl_user.user_id =" & get_user_id()
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
With rs
If .Fields("role_creation_date") = True Then
Me.cbo_dates.AddItem "role_creation_date" & "; " & "Creation Date"
If .Fields("role_anticipated_dispatch") = True Then Me.cbo_dates.AddItem "role_anticipated_dispatch" & "; " & "Dispatch to MBDA"
If .Fields("role_quote_to_customer") = True Then Me.cbo_dates.AddItem "role_quote_to_customer" & "; " & "Quote to Customer"
If .Fields("role_quote_acceptance") = True Then Me.cbo_dates.AddItem "role_quote_acceptance" & "; " & "Quote Acceptance"
If .Fields("role_quote_rejection") = True Then Me.cbo_dates.AddItem "role_quote_rejection" & "; " & "Quote Rejected"
If .Fields("role_received_at_mbda") = True Then Me.cbo_dates.AddItem "role_received_at_mbda" & "; " & "Received at MBDA"
If .Fields("role_sent_to_repairer") = True Then Me.cbo_dates.AddItem "sent_to_repaierer" & "; " & "Sent to Repairer"
If .Fields("role_received_from_repairer") = True Then Me.cbo_dates.AddItem "received_from_repaierer" & "; " & "Received from Repairer"
If .Fields("role_predicted_return_date") = True Then Me.cbo_dates.AddItem "role_predicted_return_date" & "; " & "Predicted Return"
If .Fields("role_actual_dispatch_date") = True Then Me.cbo_dates.AddItem "role_actual_dispatch_date" & "; " & "Dispatch to Customer"
If .Fields("role_received_by_customer") = True Then Me.cbo_dates.AddItem "role_received_by_customer" & "; " & "Received by Customer"
End With
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub saverecord()
Dim sql As String, db As DAO.Database, rs As Recordset
Set db = CurrentDb
sql = "SELECT tbl_vr.*, tbl_customer.customer_name, tbl_customer.customer_number, tbl_customer.customer_d_number, tbl_customer.customer_email " _
& "FROM tbl_vr INNER JOIN tbl_customer ON tbl_vr.customer_id = tbl_customer.customer_id " _
& "WHERE tbl_vr.vr_id=" & get_current_vr_id()
Set rs = db.OpenRecordset(sql, dbOpenDynaset)
With rs
.Edit
.Fields("vr_reference") = txt_vr_reference
.Fields("vr_external_reference") = txt_external_reference
.Fields("vr_project") = txt_vr_project
.Fields("part_master_id") = cbo_part_master_id
.Fields("part_master_revised_id") = cbo_part_master_revised_id
.Fields("vr_creation_date") = txt_vr_creation_date
.Fields("vr_anticipated_dispatch") = txt_vr_anticipated_dispatch
.Fields("vr_quote_to_customer") = txt_vr_quote_to_customer
.Fields("vr_quote_acceptance") = txt_vr_quote_acceptance
.Fields("vr_quote_rejection") = txt_vr_quote_rejection
.Fields("vr_received_at_mbda") = txt_vr_received_at_mbda
.Fields("vr_sent_to_repairer") = txt_vr_sent_to_repairer
.Fields("vr_received_from_repairer") = txt_vr_received_from_repairer
.Fields("vr_predicted_return_date") = txt_vr_predicted_return_date
.Fields("vr_actual_dispatch_date") = txt_vr_actual_dispatch_date
.Fields("vr_received_by_customer") = txt_vr_received_by_customer
.Fields("vr_serial_no") = txt_vr_serial_no
.Fields("customer_name") = txt_customer_name
.Fields("user_id") = txt_user_id
.Fields("customer_email") = txt_customer_email
.Fields("customer_number") = txt_customer_number
.Fields("customer_d_number") = txt_customer_number_d
.Update
End With
If Not txt_vr_creation_date = "" Or Not IsNull(txt_vr_creation_date) Then
Call UPDATE_chevron("vr_creation_date", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_creation_date", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_predicted_return_date = "" Or Not IsNull(txt_vr_predicted_return_date) Then
Call UPDATE_chevron("vr_predicted_return_date", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_predicted_return_date", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_quote_acceptance = "" Or Not IsNull(txt_vr_quote_acceptance) Then
Call UPDATE_chevron("vr_quote_acceptance", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_quote_acceptance", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_quote_rejection = "" Or Not IsNull(txt_vr_quote_rejection) Then
Call UPDATE_chevron("vr_quote_rejection", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_quote_rejection", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_quote_to_customer = "" Or Not IsNull(txt_vr_quote_to_customer) Then
Call UPDATE_chevron("vr_quote_to_customer", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("quote_to_customer", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_received_at_mbda = "" Or Not IsNull(txt_vr_received_at_mbda) Then
Call UPDATE_chevron("vr_received_at_mbda", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_received_at_mbda", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_received_by_customer = "" Or Not IsNull(txt_vr_received_by_customer) Then
Call UPDATE_chevron("vr_received_by_customer", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_received_by_customer", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_sent_to_repairer = "" Or Not IsNull(txt_vr_sent_to_repairer) Then
Call UPDATE_chevron("vr_sent_to_repairer", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_sent_to_repairer", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_anticipated_dispatch = "" Or Not IsNull(txt_vr_anticipated_dispatch) Then
Call UPDATE_chevron("vr_anticipated_dispatch", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_anticipated_dispatch", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_predicted_return_date = "" Or Not IsNull(txt_vr_predicted_return_date) Then
Call UPDATE_chevron("vr_predicted_return_date", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_predicted_return_date", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_actual_dispatch_date = "" Or Not IsNull(txt_vr_actual_dispatch_date) Then
Call UPDATE_chevron("vr_actual_dispatch_date", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_actual_dispatch_date", global_CURRENT_VR_ID, True)
End If
If Not txt_vr_received_from_repairer = "" Or Not IsNull(txt_vr_received_from_repairer) Then
Call UPDATE_chevron("vr_received_from_repairer", global_CURRENT_VR_ID, False)
Else
Call UPDATE_chevron("vr_received_from_repairer", global_CURRENT_VR_ID, True)
End If
Forms![frm_open_repairs].Requery
End Sub
the above is all the code for the form.
It seems that "unbound form", can't deal with dirty property as it is always clean.
So you can add a variable at the top of the form module and use it.

Access-VBA: How do I detect the mouse-key in a TreeView-NodeClick

I have a TreeView with a Click-Event. Since I need to implement a node-oriented dropdown-context-menu by right-click, how may I check in the existing Click-Event if the right mouse-butten was pressed. My Methode so far, looks like this:
Private Sub tvwKategorien_NodeClick(ByVal Node As Object)
Dim sBez1 As String
Dim sLangtext As String
Dim sWKZ As String
Dim sSprache As String
Dim dPreis As Double
If ((Node Is Nothing) = False) Then
If mbParseNodeKeyAndTag(Node) Then
Set moSelectedNode = Node
If msKategorie = frmArtikelgruppenRoot Then
Me.pagKategorie.Visible = False
Me.pagArtikel.Visible = False
Me.pagPicture.Visible = False
Me.pagCrosslinks.Visible = False
Me.SubArtikel.Visible = False
Me.txtKategorie = msKategorie
Me.txtBezeichnung = msBezeichnung
Me.PicArtikel.Visible = False
Call mEnableSubArtikel
Else
If mbIstNodeKategorie(moSelectedNode) Then
Me.pagKategorie.Visible = True
Me.pagArtikel.Visible = False
Me.pagPicture.Visible = False
Me.pagCrosslinks.Visible = False
Me.SubArtikel.Visible = True
Me.txtKategorie = msKategorie
Me.txtBezeichnung = msBezeichnung
Me.PicArtikel.Visible = False
If Node.Child Is Nothing Then
Dim oNodeParam As Node
Set oNodeParam = Node
Call mReadUntergruppen(oNodeParam, oNodeParam.Key, gnCInt(gsParameter(oNodeParam.Text, "Gruppenebene")) + 1)
End If
Call mEnableSubArtikel
Dim rs As Recordset
Set rs = Me.SubArtikel.Form.Recordset
If Not rs Is Nothing Then
Call mReadArtikel(Node, Node.Key, gnCInt(gsParameter(Node.Text, "Gruppenebene")) + 1)
Node.Expanded = True
Else
Node.Expanded = False
End If
Else
Me.pagKategorie.Visible = False
Me.pagArtikel.Visible = True
Me.pagPicture.Visible = True
Me.pagCrosslinks.Visible = True
Me.SubArtikel.Visible = False
Me.txtArtNr = msBezeichnung
Me.txtArt = msBezeichnung & " " & gvntLookup("Matchcode", "KHKArtikel", "Artikelnummer='" & msBezeichnung & "' AND Mandant=" & gnManId, "")
cbBild.Value = "ITPWeb_"
Call mInitPicture
nil = gITPWebGetArtPreis(msBezeichnung, 0, sWKZ, dPreis, cbShop.Value)
Me.txtArtPreis = dPreis
Me.txtArtWkz = sWKZ
If gvntNull2Arg(cboSprache, "") = "" Then
sSprache = "W" & gvntManProperty(22)
Else
sSprache = CStr(cboSprache)
End If
nil = gITPWebGetArtBez(sSprache, msBezeichnung, sBez1, sLangtext)
Me.txtArtBezeichnung = sBez1
Me.txtArtLangtext = sLangtext
msAktuelleKategorie = Split(Node.Key, ";")(0)
Me.cboBonusprodukt.Locked = False
sSplit = Split(Node.Key, ";")
Me.cboBonusprodukt.Value = gvntLookup("BonusProduct", "ITPWebKategorienArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId & " and Kategorie = " & gsStr2Sql(msAktuelleKategorie) & " and Pos = " & sSplit(getArrayLenght(sSplit)), 0)
Me.cboBonusprodukt.AllowValueListEdits = False
Me.txtBonuspunkte = gvntNull2Arg(gvntLookup("Bonuspunkte", "ITPWebKategorienArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId & " and Kategorie = " & gsStr2Sql(msAktuelleKategorie) & " and Pos = " & sSplit(getArrayLenght(sSplit)), 0), 0)
Me.chkOrderable = gvntLookup("USER_ITPWebOrderable", "KHKArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId, -1)
Me.chkShopActive = gvntLookup("USER_ITPWebShopActive", "KHKArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId, -1)
Me.chkPricePush = gvntLookup("USER_ITPWebPricePush", "KHKArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId, 0)
Call mEnableSubCrosslinks
End If
End If
End If
End If
tvwKategorien_NodeClick_Error:
End Sub
I'm working inside an access-document with VBA :(
You have to use MouseDown event for your tree tvwKategorienand flag some module variable in order to check later it in NodeClick
put this at the beginning of the Module but after Option strings
private MouseButton as Integer
Add MouseDown event
Private Sub tvwKategorien_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
MouseButton =Button
End Sub
Then use such condition to detect right click in your existing NodeClick event
If MouseButton = acRightButton Then ' right
and
If MouseButton = acLeftButton Then ' left