ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Fields in recordset from Access with value Null (empty fields) (https://www.excelbanter.com/excel-programming/373256-fields-recordset-access-value-null-empty-fields.html)

Mats Nilsson

Fields in recordset from Access with value Null (empty fields)
 
Hi All,
In an Excel VBA routine data from Access are reported to an Excelsheet with
recordsets and loops for the number of items.
It works OK when the field have got values but I can´t get it to work with
empty fields (value Null).

I have tried like this
"If rs1.Fields("TextCell").Value = Null Then
Else
strCelltext = rs1.Fields("TextCell").Value"
but even if the field is empty it will get on to the line after Else.
Thanks in advance with any help.
All the best
Mats


--
ESI Update

Bill Pfister

Fields in recordset from Access with value Null (empty fields)
 
Use an intermediate function to handle errors. For example:

public function NotNull( rsRecord as object ) as string
on error goto ErrHandler

NotNull = rsRecord

exit function
ErrHandler:
NotNull = ""
end function

....
strCelltext = NotNull( rs1.Fields("TextCell") )
....


"Mats Nilsson" wrote:

Hi All,
In an Excel VBA routine data from Access are reported to an Excelsheet with
recordsets and loops for the number of items.
It works OK when the field have got values but I can´t get it to work with
empty fields (value Null).

I have tried like this
"If rs1.Fields("TextCell").Value = Null Then
Else
strCelltext = rs1.Fields("TextCell").Value"
but even if the field is empty it will get on to the line after Else.
Thanks in advance with any help.
All the best
Mats


--
ESI Update


Mats Nilsson

Fields in recordset from Access with value Null (empty fields)
 
Hi Bill,
Thanks for your answer.
I found the function isnull(expression) in the VBA help and I think that
function also will work.
/Mats

--
ESI Update


"Bill Pfister" wrote:

Use an intermediate function to handle errors. For example:

public function NotNull( rsRecord as object ) as string
on error goto ErrHandler

NotNull = rsRecord

exit function
ErrHandler:
NotNull = ""
end function

...
strCelltext = NotNull( rs1.Fields("TextCell") )
...


"Mats Nilsson" wrote:

Hi All,
In an Excel VBA routine data from Access are reported to an Excelsheet with
recordsets and loops for the number of items.
It works OK when the field have got values but I can´t get it to work with
empty fields (value Null).

I have tried like this
"If rs1.Fields("TextCell").Value = Null Then
Else
strCelltext = rs1.Fields("TextCell").Value"
but even if the field is empty it will get on to the line after Else.
Thanks in advance with any help.
All the best
Mats


--
ESI Update



All times are GMT +1. The time now is 09:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com