咨询Access 2016中64位整数(bigint)对应的最佳VBA数据类型
最佳VBA数据类型对应Access 2016的BigInt字段
Great question—this is such a common pain point when working with 64-bit integers in Access, especially when dealing with linked tables. Let’s break this down clearly: the perfect VBA data type for Access 2016’s bigint fields is LongLong.
Why LongLong is exactly what you need
- It’s a native 64-bit signed integer type (supported in VBA 7.0 and later, which Access 2016 uses by default). Its range (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807) matches perfectly with the standard SQL
bigintdata type—so you’ll never hit overflow issues when moving values between your VBA variables and Access tables/linked tables. - Unlike
Variant Decimal, it’s a value type (not wrapped in a variant), so it’s far more efficient in terms of memory and performance. No unnecessary overhead here—just a straight-up integer that does exactly what you need.
How to use it in practice
Declare your variables like this:
Dim orderID As LongLong Dim totalRecords As LongLong
Reading from a recordset is straightforward:
orderID = rs!OrderBigIntID ' rs is your DAO or ADO recordset
Writing back to a table works just as seamlessly:
rs!OrderBigIntID = orderID rs.Update
Edge cases to consider
- If you’re dealing with unsigned 64-bit integers (a rare scenario in Access/SQL),
LongLongwon’t cut it since it’s signed. In that case, you’d have to fall back toVariant Decimal, but this is unlikely to be your use case. - For Access versions older than 2010,
LongLongisn’t available—but since you’re using 2016, this isn’t something you need to worry about.
Why the alternatives you mentioned aren’t ideal
Longis only 32-bit, maxing out at 2,147,483,647. It’s way too small for bigint values, which will lead to frustrating overflow errors.Variant Decimalis overkill: it’s a 128-bit type designed for high-precision decimals, not just plain integers. The variant wrapper adds unnecessary memory usage and performance lag when all you need is a simple 64-bit whole number.
内容的提问来源于stack exchange,提问作者AndyDev
相关产品推荐
相关产品推荐

