Copying row in ListBox, and Date VarType doesn't copy

donwiss

Board Regular
Joined
Jul 5, 2020
Messages
63
Platform
  1. Windows
I have a multi-column ListBox. It is populated from Access using .GetRows and .List. One of the columns from Access is Date/Time. If the data is extracted from the ListBox, the data type for the timestamp column is Variant/Date.

I'd like to copy a row. Just copying the timestamp cell from the old row to the newly added row turns the VarType to Variant/String. So I figured I use CDate() when copying. Nope. Still Variant/String.

I need all in the column to be Date type, so my sort can correctly work.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
The values in a textbox don't really have a data type, they are all essentially strings.

How are you 'copying' the values?
 
Upvote 0
But after the initial population of the ListBox, extracting the data shows Variant/Date. So Access is able to pass on its Date/Time format.

VBA Code:
ListBox1.AddItem NewName
ListBox1.List(ListBox1.ListCount - 1, 1) = CDate(ListBox1.List(i, 1))

Later when sorting, I can't use DateValue() as it returns only the date, and I also want the time.
 
Upvote 0
How are you extracting the data?

P.S. Is this Access or Excel or both?
 
Upvote 0
This is Excel VBA, using DAO to pull data from Access to populate the ListBox. There are no WorkSheets in the application I'm working on. It's all Access and UserForms. Driven by a CommandBar.
 
Upvote 0
How/where is this causing problems?
 
Upvote 0
I need all in the column to be Date type, so my sort can correctly work.

Instead of copying that cell from the old row to the new row, I figured I could simply retrieve that cell from Access (the file is already open, as I also copied the row in the table) and put that into the cell. Nope. Becomes a string. Apparently filling the entire .List is different from filling a single cell.

What I can do, instead of Adding an Item, is to get the whole list from Access again.
 
Upvote 0
Like I said, columns in a listbox do not have a data type.
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,289
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top