By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,773 Members | 2,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,773 IT Pros & Developers. It's quick & easy.

Long versus Integer

P: 14
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
Share this Question
Share on Google+
4 Replies


Expert Mod 2.5K+
P: 2,545
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
Expert 2.5K+
P: 3,072
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

P: 14
@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

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

Post your reply

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