Andy Lacey
andy at minstersystems.co.uk
Fri Jul 30 05:39:27 CDT 2004
Pedro Not such a dim question I didn't think ;-) With the dim outside the function it doesn't get reinitialised for each call, so when you're adding to it it's starting from a value. You'd need to put: lngPnrCount=0 at the top of the function. -- Andy Lacey http://www.minstersystems.co.uk --------- Original Message -------- From: Access Developers discussion and problem solving <accessd at databaseadvisors.com> To: AccessD at databaseadvisors.com <AccessD at databaseadvisors.com> Subject: [AccessD] dim question Date: 30/07/04 09:36 > > Hello Group, > > Why do i get different results with the function below when placing dim inside and outside the function. > > <code> > > Option Compare Database > > Dim strLastPnr As String > Dim lngPnrCount As Long > > Function NumberRecs(strPnr As String) As Long > > If strPnr <> strLastPnr Then > lngPnrCount = 1 > strLastPnr = strPnr > NumberRecs = 1 > Else > lngPnrCount = lngPnrCount + 1 > NumberRecs = lngPnrCount > End If > > End Function > > > <code> > > as result i get > > Pnr field Exp1 > 0001 t1 1 > 0001 t2 2 > 0001 t3 3 > 0005 t1 1 > 0006 t1 1 > > > > > <code> > > Option Compare Database > > Function NumberRecs(strPnr As String) As Long > > Dim strLastPnr As String > Dim lngPnrCount As Long > > > If strPnr <> strLastPnr Then > lngPnrCount = 1 > strLastPnr = strPnr > NumberRecs = 1 > Else > lngPnrCount = lngPnrCount + 1 > NumberRecs = lngPnrCount > End If > > End Function > > > <code> > > as result i get > > Pnr field Exp1 > 0001 t1 1 > 0001 t2 1 > 0001 t3 1 > 0005 t1 1 > 0006 t1 1 > > > > TIA > > Pedro Janssen > > -- > _______________________________________________ > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > > > > > ________________________________________________ Message sent using UebiMiau 2.7.2