Just a quick one on Clng Vs CInt (1 Viewer)

nector

Member
Local time
Today, 22:48
Joined
Jan 21, 2020
Messages
368
I have a field in Ms access table which has data type = Long integer, now I want to use unbound form to update that field with a control not bound to a table how do I much the data type to Long integer

I'm gambling on Clng or CInt functions , for example CInt(Me.txtEsDFinInvoice) , represent the invoice number from Json string

What should I do in case to archive the same data type as per table (long integer) the complete data is being received via Json format that is I need the correct data type to avoid an overflow. Without fixing the data type correctly then I will risking loss of data

Code:
'Processing data from the string above
    Set db = CurrentDb
Set Rs = db.OpenRecordset("tblEfdReceipts", dbOpenDynaset)
    Set json = JsonConverter.ParseJson(strDataAudit)
    Dim Z as integer
    'Process data.
    Z = 1
    For Each Details In json
        Rs.AddNew
        Rs![ESDTime] = CDate(Format$(Details("ESDTime"), "00/00/00 00:00:00"))
        Rs![TerminalID] = Details("TerminalID")
        Rs![InvoiceCode] = Details("InvoiceCode")
        Rs![InvoiceNumber] = Details("InvoiceNumber")
        Rs![FiscalCode] = Details("FiscalCode")
        Rs![INVID] = CInt(Me.txtEsDFinInvoice)
        Rs.Update
        Z = Z + 1
    Next
 
    Rs.Close
    Set Rs = Nothing
    Set db = Nothing
    Set json = Nothing
    Set Details = Nothing
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:48
Joined
Oct 29, 2018
Messages
21,476
I would bet on using CLng().
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:48
Joined
May 21, 2018
Messages
8,533
A long and int field can accept a variable that is either of datatype long or int as long as it was in range
So even if the field was Int field and you did a Clng it would work as long as that value was in the int range.

If the table field was lng and you did an Cint it would work too, If would fail if the thing you are converting is outside the range. This would fail in vba cint function, not at the insert.

Both would fail for numbers outside the long data type

IntegerAllows whole numbers between -32,768 and 32,7672 bytes
LongAllows whole numbers between -2,147,483,648 and 2,147,483,6474 bytes

 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 20:48
Joined
Feb 19, 2013
Messages
16,618
On a separate issue, I would just watch your date format

"00/00/00 00:00:00"

formatting in the immediate window you get

?format(now(),"00/00/00 00:00:00")
00/00/00 04:47:98

suggest you need to use

"yyyy-mm-dd hh:nn:ss"

plus your json date is already a string so you may not need to format it, or you need to rearrange it - CDate will intreprete based on local format based on month and date being in the right 'place' - in US format 12/01/20" will be interpreted as 1st December, whilst in the UK it will be 12th Jan

generally better to use the SQL standard of "yyyy-mm-dd"
 

Users who are viewing this thread

Top Bottom