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 / March 2008

Tip: Looking for answers? Try searching our database.

for loop problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
billypit786@gmail.com - 04 Mar 2008 20:25 GMT
Hi,
My project is in MS Access 2002.
In that I have one form. In that I want to put For or Do While loop.
I want thing like this in Access.
This is in C++ format.

Quote:
Originally Posted by
for(int i=1,j=17;i<=26,j<=32;i++,j++)
{
If ((Me.ItemNo[i+1] = Me.ItemNo[i]) And (Me.NoOfCartons[i+1] =
Me.NoOfCartons[i]) And (Me.NoOfPiecesPerPartialCartons[i+1] = 0) And
(Me.BatchOrLotNo[i+1] = Me.BatchOrLotNo[i]) And (Me.LONo[i+1] =
Me.LONo[i])) Then
Me.NoOfPallet[i] = Me.NoOfPallet[i+1] + 1
Me.TotalPieces[i] = (([NoOfPallet[i+1]] * ([NoOfCartons[i+1]] *
[NoOfPiecesPerCartons[i])))
Me.PalletNo[i] = Me.PalletNo[i] + ";" + Me.PalletNo[i+1]
Me.PalletNo[i+1] = Null
Me.ItemNo[i+1] = Null
Me.Description[i+1] = Null
Me.NoOfPallet[i+1] = Null
Me.NoOfCartons[i+1] = Null
Me.NoOfPiecesPerCartons[i+1] = Null
Me.NoOfPartialCartons[i+1] = Null
Me.NoOfPiecesPerPartialCartons[i+1] = Null
Me.NoOfPartialCartons[j+1] = Null
Me.NoOfPiecesPerPartialCartons[j+1] = Null
Me.TotalPieces[i+1] = Null
Me.BatchOrLotNo[i+1] = Null
Me.PONo[i+1] = Null
Me.LONo[i+1] = Null
Me.PalletNo[i+1].SetFocus
}

but it shows error.
Loop is ok but I am using [i] and [i+1] i think that's not right.I
think it array something but I don't know how to do it?
any solution of this thing?
Thanks.
Douglas J. Steele - 04 Mar 2008 20:37 GMT
If your intent is to take data from one row and write it to another row, you
can't do it in that manner. Access doesn't support control arrays, so
concepts like Me.ItemNo[i+1] = Me.ItemNo[i] are meaningless in VBA.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hi,
> My project is in MS Access 2002.
[quoted text clipped - 36 lines]
> any solution of this thing?
> Thanks.
billypit786@gmail.com - 05 Mar 2008 13:38 GMT
So what's the solution for it?
Do I have to write it for all 26 fields? It will be too long if  I
write it for all 26 fields.
Thanks For ur reply.
Douglas J. Steele - 05 Mar 2008 14:45 GMT
In other words, you're not simply returning a bunch of rows as the detail of
the form? You're actually populating 26 sets of controls with values? Sounds
unusual, but if that's the case you can simulate control arrays by using
naming conventions for your controls.

For instance, if you name your controls ItemNo1, ItemNo2, ItemNo3 and so on
upto ItemNo26, NoOfCartons1, NoOfCartons2, and so on to  NoOfCartons26 and
so on, you could use code like:

For i = 1 To 25
 If ((Me.Controls("ItemNo" & (i+1)) = Me.Controls("ItemNo" & i) _
   And (Me.Controls("NoOfCartons" & (i+1)) = Me.Controls("NoOfCartons" & i)
_
   And (Me.Controls("NoOfPiecesPerPartialCartons" & (i+1)) = 0) _
   And (Me.Controls("BatchOrLotNo" & (i+1)) = Me.Controls("BatchOrLotNo" &
i) _
   And (Me.Controls("LONo" & (i+1)) = Me.Controls("LONo" & i)) Then

   Me.Controls("NoOfPallet" & i) = Me.Controls("NoOfPallet" & (i+1)) + 1
   Me.Controls("TotalPieces" & i) = ((Me.Controls("NoOfPallet" & (i+1)) * _
     (Me.Controls("NoOfCartons" & (i+1)) *
Me.Controls("NoOfPiecesPerCartons" & i)))

etc

Next i

(Note that if you've only got 26 controls, the sample code you posted would
have failed, since it loops until i is 26, and then looks for control i+1)

If, on the other hand, you actually have a "normal" form, with one set of
controls that is replicated for each row in the form's recordsource, it's
not possible to refer to individual controls like that. You'd have to work
with the form's recordset.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> So what's the solution for it?
> Do I have to write it for all 26 fields? It will be too long if  I
> write it for all 26 fields.
> Thanks For ur reply.
billypit786@gmail.com - 05 Mar 2008 15:19 GMT
Hey thanks for ur help.
 
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.