Hi All,
I query an SQL Database via VBA and wish to return results from the recordset into variables.
The problem is that some of the fields, although populated on the Database, don't show values in VBA, or, they show values, but then mysteriously change to 'Null' when I try to do anything with them.
Specifying specific fields to query, and changing the field order in the SQL SELECT code seems to change the amount of populated fields too.
Why is this and what's going on?!
My Query is as follows:
sSQL = "SELECT * " & _
"FROM " & _
"dtblPEN0001Jobs, " & _
"dtblPEN0001Options " & _
"WHERE " & _
"dtblPEN0001Options.Reference='" & sPropertyRef & "' " & _
"AND dtblPEN0001Jobs.Reference='" & sLeaseRef & "' " & _
"AND dtblPEN0001Jobs.OptionID = dtblPEN0001Options.OptionID"
oDatabase.Open sSQL, _
oConnection, _
adOpenForwardOnly, _
adLockReadOnly, _
adCmdText
' Then I populate my variables with the returned results:
If IsNull(oDatabase("S_Site_Status")) = False Then sPropertyStatus = oDatabase("S_Site_Status")
If IsNull(oDatabase("N_Property_Area")) = False Then sPropertyArea = oDatabase("N_Property_Area")
' However some field types, although 'LEN' shows as having a length, and tooltip help showing the value, change to 'NULL' when I try to add them to a variable:
If Len(oDatabase("M_Repair_Obligations")) > 0 Then sRepairObligations = oDatabase("M_Repair_Obligations")
If Len(oDatabase("M_Insurance_Obligations")) > 0 Then sInsuranceObligations = oDatabase("M_Insurance_Obligations")
' --------------
On the lower two rows, Len(oDatabase("M_Repair_Obligations")) returns '84', but then the field shows as NULL, and produces an error when I try to add it to a field. All other fields below this (beginning with M_) then show NULL too - even though their LEN values are greater than zero.
Any help would be greatly appreciated!
Mav3000
I query an SQL Database via VBA and wish to return results from the recordset into variables.
The problem is that some of the fields, although populated on the Database, don't show values in VBA, or, they show values, but then mysteriously change to 'Null' when I try to do anything with them.
Specifying specific fields to query, and changing the field order in the SQL SELECT code seems to change the amount of populated fields too.
Why is this and what's going on?!
My Query is as follows:
sSQL = "SELECT * " & _
"FROM " & _
"dtblPEN0001Jobs, " & _
"dtblPEN0001Options " & _
"WHERE " & _
"dtblPEN0001Options.Reference='" & sPropertyRef & "' " & _
"AND dtblPEN0001Jobs.Reference='" & sLeaseRef & "' " & _
"AND dtblPEN0001Jobs.OptionID = dtblPEN0001Options.OptionID"
oDatabase.Open sSQL, _
oConnection, _
adOpenForwardOnly, _
adLockReadOnly, _
adCmdText
' Then I populate my variables with the returned results:
If IsNull(oDatabase("S_Site_Status")) = False Then sPropertyStatus = oDatabase("S_Site_Status")
If IsNull(oDatabase("N_Property_Area")) = False Then sPropertyArea = oDatabase("N_Property_Area")
' However some field types, although 'LEN' shows as having a length, and tooltip help showing the value, change to 'NULL' when I try to add them to a variable:
If Len(oDatabase("M_Repair_Obligations")) > 0 Then sRepairObligations = oDatabase("M_Repair_Obligations")
If Len(oDatabase("M_Insurance_Obligations")) > 0 Then sInsuranceObligations = oDatabase("M_Insurance_Obligations")
' --------------
On the lower two rows, Len(oDatabase("M_Repair_Obligations")) returns '84', but then the field shows as NULL, and produces an error when I try to add it to a field. All other fields below this (beginning with M_) then show NULL too - even though their LEN values are greater than zero.
Any help would be greatly appreciated!
Mav3000