Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / April 2005

Tip: Looking for answers? Try searching our database.

Compile Error: Constant Expression Required

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Software Cub - 04 Apr 2005 17:42 GMT
I receive the above error message when trying to execute the below code. The
For...Next loop increment variable, I, is highlighted. What is wrong with the
code. Is it a declaration error?
Signature

Software Cub.

The Code is:

   Dim intNumberOfForkLiftTests As Integer
   Dim intIncrementTopRange As Integer
   Dim I As Integer
   Dim strForkLiftPersonTested As String
   
   If SpecialInstructions > 0 Then
       SpecialInstructions = SpecialInstructions & Chr(13) & Chr(10) &
"Forklift Testing For:" & _
       Chr(13) & Chr(10) & "     "
   Else
       SpecialInstructions = "Forklift Testing For:" & Chr(13) & Chr(10) &
"     "
   End If
   
   intNumberOfForkLiftTests = InputBox("Enter the Number of Fork Lift Tests
Administered.")
   
   intIncrementTopRange = intNumberOfForkLiftTests
   
   For I = 1 To intIncrementTopRange
       Dim strName(I) As String
       strForkLiftPersonTested = InputBox("Enter the Name of the Fork Lift
Person Tested.")
       strName(I) = strForkLiftPersonTested
       If I = 1 And I = intIncrementTopRange Then
           SpecialInstructions = SpecialInstructions & strName(I) & "."
       ElseIf I = 1 And (I + 1) = intIncrementTopRange Then
           SpecialInstructions = SpecialInstructions & strName(I) & ", And "
       ElseIf I = 1 And (I + 1) < intIncrementTopRange Then
       SpecialInstructions = SpecialInstructions & strName(I) & ", "
       ElseIf I > 1 Then
           If I Mod 2 = 0 And I = intIncrementTopRange Then
               SpecialInstructions = SpecialInstructions & strName(I) & "."
           ElseIf I Mod 2 = 0 And (I + 1) = intIncrementTopRange Then
               SpecialInstructions = SpecialInstructions & strName(I) & ",
And" & Chr(13) & Chr(10) & "     "
           ElseIf I Mod 2 = 0 And (I + 1) < intIncrementTopRange Then
               SpecialInstructions = SpecialInstructions & strName(I) & ","
& Chr(13) & Chr(10) & "     "
           ElseIf I Mod 2 > O And I = intIncrementTopRange Then
               SpecialInstructions = SpecialInstructions & strName(I) & "."
           ElseIf I Mod 2 > O And (I + 1) = intIncrementTopRange Then
               SpecialInstructions = SpecialInstructions & strName(I) & ",
And "
           ElseIf I Mod 2 > O And (I + 1) < intIncrementTopRange Then
               SpecialInstructions = SpecialInstructions & strName(I) & ", "
           End If
       End If
   Next I
   
   SpecialInstructions = SpecialInstructions & Chr(13) & Chr(10) &
"Dispensed on " & DateDispensed
   
   Refresh

Brendan Reynolds - 04 Apr 2005 19:05 GMT
Perhaps your I (uppercase letter i) is really a 1 (digit one) or an l
(lowercase letter L) They can be very difficult to distinguish in some
fonts. For this reason, if you use single-letter variable names at all, it
is better to always use lowercase. Try changing your 'I' to 'i'.

Signature

Brendan Reynolds (MVP)

>I receive the above error message when trying to execute the below code.
>The
> For...Next loop increment variable, I, is highlighted. What is wrong with
> the
> code. Is it a declaration error?
Software Cub - 04 Apr 2005 22:13 GMT
Sorry Brenden,

That's not the problem.

Steve

> Perhaps your I (uppercase letter i) is really a 1 (digit one) or an l
> (lowercase letter L) They can be very difficult to distinguish in some
[quoted text clipped - 6 lines]
> > the
> > code. Is it a declaration error?
Brendan Reynolds - 05 Apr 2005 08:54 GMT
Well, in a way, it is.

First, though, there's another problem. It's the dynamic array. You need to
declare the array first, then redimension it with ReDim. In other words,
instead of ...

   For I = 1 To intIncrementTopRange
       Dim strName(I) As String

... you need to do this ...

   Dim strName() As String
   For I = 1 To intIncrementTopRange
       ReDim strName(I)

The 'Dim' line could, of course, be at the top of the procedure with your
other declarations, I've put it in here just to make it easy to compare it
with the original code.

So, what did I mean by 'in a way, it is'? Well, further down in the code,
you have this ...

           ElseIf I Mod 2 = 0 And (I + 1) < intIncrementTopRange Then
               SpecialInstructions = SpecialInstructions & strName(I) &
"," & Chr(13) & Chr(10) & "     "
          ElseIf I Mod 2 > O And I = intIncrementTopRange Then

I'm pretty sure that capital 'O' in the third line should be a zero! :-)

Signature

Brendan Reynolds (MVP)

> Sorry Brenden,
>
[quoted text clipped - 14 lines]
>> > the
>> > code. Is it a declaration error?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.