473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Long versus Integer

Hi:

I'm running into an overflow problem with the following code (with the variable nCNOS), but get a compile error (AddInvoice rsInvoice, nRNOS, nCNOS) if I change it to Long. Can someone help?

Expand|Select|Wrap|Line Numbers
  1.     Dim stDocName As String
  2.     Dim nRetreatNumber As Integer
  3.     Dim nRNOS As Integer
  4.     'Dim nCNOS As Integer
  5.     Dim nCNOS As Long
  6.  
  7.     'check whether there is a customer number
  8.     nRNOS = Forms!frmSpecialEventsEnterDeleteModify.RNOS
  9.     nCNOS = Forms!frmSpecialEventsEnterDeleteModify.Text191
  10.     Dim Msg, Style, Title, Help, Ctxt, Response, MyString
  11.  
  12.     If IsNull(nCNOS) Or nCNOS = 0 Then
  13.         Msg = "You must select a person to bill before you can create an invoice"
  14.         Style = vbOK + vbCritical
  15.         Title = "Select a person to bill"
  16.         MsgBox Msg, Style, Title
  17.         Exit Sub
  18.     End If
  19.  
  20.     Dim sWhere As String
  21.     Dim rsInvoice As ADODB.Recordset
  22.     Dim rsCount As ADODB.Recordset
  23.  
  24.     nRNOS = Forms!frmSpecialEventsEnterDeleteModify.[RNOS]
  25.     Set rsCount = New ADODB.Recordset
  26.     Set rsInvoice = New ADODB.Recordset
  27.     sWhere = "SELECT * FROM tblInvoice WHERE RNOS = " & nRNOS & ""
  28.     rsCount.Open sWhere, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
  29.  
  30.     'check if an invoice already exists for this event
  31.     If rsCount.EOF Then
  32.         rsInvoice.Open "tblInvoice", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
  33.         AddInvoice rsInvoice, nRNOS, nCNOS
  34.         rsInvoice.Close
  35.         stDocName = "rptInvoiceForSpecialEvents"
  36.         DoCmd.OpenReport stDocName, acPreview
  37.     Else
  38.         stDocName = "rptInvoiceForSpecialEvents"
  39.         DoCmd.OpenReport stDocName, acViewPreview
  40.     End If
Feb 15 '09 #1
4 2332
Stewart Ross
2,545 Expert Mod 2GB
Hi. You don't show your code for AddInvoice, so I am just guessing here - is the second parameter for AddInvoice defined as an integer? If it is, passing a Long when an Integer type is expected will cause an error. You would need to change the Integer definition in AddInvoice to Long for compatibility.

Otherwise, there is no obvious problem with the code posted.

-Stewart
Feb 15 '09 #2
nico5038
3,080 Expert 2GB
Assigning text to a number field:
nCNOS = Forms!frmSpecialEventsEnterDeleteModify.Text191
looks odd.
You could use Val() like:
nCNOS = val(Forms!frmSpecialEventsEnterDeleteModify.Text19 1 )
to turn the textfield into a (long) number, but I would probably keep the field having the same datatype as in the original table.

An alternative I often use is to have a combobox holding a DISTINCT value for the personID so the user can only select existing values...

Nic;o)
Feb 15 '09 #3
@Stewart Ross Inverness
Thanks Stewart! How blind am I? Of course, when I look at the AddInvoice code, CNOS it is defined as an Integer....

All works well now.

Thanks!
Feb 15 '09 #4
@nico5038
Thanks! I'll try your suggestion...
Thanks for the quick reply.
Feb 15 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

45
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286)...
12
by: Peter Ammon | last post by:
When I add an unsigned long long and an int, what type do each of the values get promoted to before the addition is performed? What is the type of the resulting expression? What occurs if the...
3
by: Mike Miller | last post by:
What is the best way to convert a managed unsigned int64 to an unsigned long? Basically I need to do the following: System::UInt64 managedInt = 10; unsigned long unmanagedInt; unmanagedInt =...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
2
by: Jon Lapham | last post by:
I have a table that stores TEXT information. I need query this table to find *exact* matches to the TEXT... no regular expressions, no LIKE queries, etc. The TEXT could be from 1 to 10000+...
73
by: Yevgen Muntyan | last post by:
Hey, I was reading C99 Rationale, and it has the following two QUIET CHANGE paragraphs: 6.5.3.4: "With the introduction of the long long and extended integer types, the sizeof operator may...
24
by: Paulo Matos | last post by:
Hello, Is it safe to assume a size_t is an unsigned long? (is it forced by the standard?) Thank you, Paulo Matos
4
by: Tim | last post by:
Hello All, I could use some help on an error that is just now popping it's head up. Seems that the autoincrement numeric has hit 32,767. The autoincrement is used in various locations in the...
2
by: snorble | last post by:
I started creating a simple "bits" class, intended to act like a array of bits. This was my initial idea, basically just overriding the string representation to display the bitmask (so far): ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.