Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88111

Runtime Error 13 when TextBox containing a Date is empty

$
0
0

Despite of checking many questions relating error 13, I could not find answers to my problem, so I am giving a shot here:

I am building my code to save information from a userform, but first I am testing to see if mandatory textboxes are empty. Since I am using a 64 bits machine I have used Trevor Eyre´s CalendarForm.

However while testing the code I hit a problem with the empty textboxes that receives the dates from CalendarForms:

In this line:

Dim dteCompraDataOps As Date: dteCompraDataOps = Me.txtTesouro_Compra_DataOps.value

This part is highlighted and returns Runtime Error 13:

dteCompraDataOps = Me.txtTesouro_Compra_DataOps.value 

When I check the values coming from empty TextBoxes I get:

dteCompraDataOps = "00:00:00"` 

Which is correct since it should be treated as Date, but this:

Me.txtTesouro_Compra_DataOps.value = ""

Is coming as a string.

I did a little search and noticed that Date data types are tricky when the textbox they come from are empty.

I could find a solution: creating a Select Case to test the mandatory fields before declaring the variables but I would like o learn how to deal with the empty textboxes that are supposed to be empty.

Any chance you can shed some light into my conundrum?

Thanks in advance. Cub4_RJ


Viewing all articles
Browse latest Browse all 88111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>