473,806 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sequentially numbering a field !

Hi !

I have a field "sub_tran_n o" in my form in continuous view.

When the user presses a button "Re-Number", I'd like to:

1) Save the current record pointer position
2) Save the current field which has focus
3) go to the top of the recordset & start re-numbering
the "sub_tran_n o" field with the values 1,2,3, until eof.
4) go back to the previous record number
5) set focus to the last field.
6) Refresh the form to display the results

Should I do this using Recordset or RecordsetClone.

Could anyone please help with a little Air-Code ?

Thx & Best Rgds,
Prakash.

Nov 13 '05
20 2071
What did you requery? The rst variable (pointing to the recordsetclone) ?
Or the form?

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea

Nov 13 '05 #11
I've tried every possible permutation & combination. ReQuerying the
Form, the RecordsetClone, even the Recordset, I've even tried SETting
the RecrdsetClone to the Recordset object & received some errors ...
basically everything conceiveable ... but to no avail.

The same problem persists: If I delete ALL records from the
RecordsetClone, it loses it's sync with the RecordSet & needs the form
to be closed & re-opened to be re-synched.

Any more ideas ... I'm really desperate now ...

-----------------------------------------------------------------------

Now here's something else ... instead of operating on RecordsetClone, I
tried RecordSet & now it works perfectly albeit I'd have preferred
RecordSetClone as the record pointer seems to "dance around" a lot with
the RecordSet.

There's another problem here now though: I'm losing my row position as
I delete records. I tried bookmark, but when I keep deleting rows I
eventually get the error msg: "No Current Record".

Any ideas ?
I'd really like to thank you sincerely for all the time & effort you've
put ino this.

Thx & Bst Rgds,
Prakash.

Nov 13 '05 #12
OK !! I've FINALLY managed to get it working using RECORDSET (not
recordsetclone) .

1 teeny-weeny irritance however:
The Record Pointer keeps dancing up & down in my continuous form (never
used to happen with recordsetclone) . Is there any way to avoid this ?

Thx & Best Rgds,
Prakash

Nov 13 '05 #13
Sorry for posting in a hurry.

I did an Application.ech o false and Application.ech o.true & the
dance stopped.

BTW, is Application.ech o better or DoCmd.Echo & why ?

Also, any caveats to using either ?

Bas ... a big thanks to you & Wayne once again.
(Would you like me to post my final code here) ?

Rgds,
Prakash.

Nov 13 '05 #14
Dancing up and down... No idea. What event does this happen in? What is
the code for the corresponding event handler? If all else fails,
however, one trick I apply sparingly is docmd.echo false--offending
statements--docmd.echo true. Don't forget to include an error handler
that does docmd.echo true as well, in that case.

With Access, my directions have almost always been: use this object; if
it misbehaves, use another. So you've found that trail too. :-)

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea

Nov 13 '05 #15
> BTW, is Application.ech o better or DoCmd.Echo & why ?

Dunno. I'm still used to docmd, I guess.
Also, any caveats to using either ?


The general idea of trapping error and setting Echo on again. You have
no clue as to what happens/happened when an error occurs during echo
off. Can you type blindly? I learned :-)
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea

Nov 13 '05 #16
To the best of my knowledge, DoCmd.Echo and Application.Ech o should both do
the same thing. Application.Ech o is the newer command; therefore,
theoretically better.

The problem mentioned with the error trapping is why I include an Echo On in
my error handler whenever I use Echo Off in the code. That way if an error
occurs, I can get to the application to work on it.

--
Wayne Morgan
MS Access MVP
"Bas Cost Budde" <b.*********@he uvelqop.nl> wrote in message
news:da******** **@localhost.lo caldomain...
BTW, is Application.ech o better or DoCmd.Echo & why ?


Dunno. I'm still used to docmd, I guess.
Also, any caveats to using either ?


The general idea of trapping error and setting Echo on again. You have no
clue as to what happens/happened when an error occurs during echo off. Can
you type blindly? I learned :-)
--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea

Nov 13 '05 #17
Here's the Final Working Code:

Private Sub Form_Current()
Dim msg As String, msg1 As String, msg2 As String, msg3 As String

Me.DETAILS.Cont rolTipText = Nz(Me.DETAILS)
'MsgBox "Current Record Number: " & Me.CurrentRecor d
'LbL_Tran_No.Ca ption = "Transactio n No: " & DMax("Tran_No",
"DPATDAT") + 1

If Me.NewRecord = True And Me.Sub_Tran_No >= 254 Then
'MsgBox "New Record !"
msg1 = "MAXIMUM ROWS/TRANSACTIONS ALLOWED ARE 255 !" & Chr(13)
& Chr(13)
msg2 = "Please Delete Some Rows !"
MsgBox msg1 & msg2, vbOKOnly + vbCritical, "Error !"
SendKeys "^{PGUP}", True
Screen.Previous Control.SetFocu s
End If

If Me.Recordset.Re cordCount = 0 Then
'MsgBox "Empty Table !"
Me.Sub_Tran_No. DefaultValue = 1
Else
Me.Sub_Tran_No. DefaultValue = DMax("sub_tran_ no", "JVTable") +
1
End If

End Sub


Private Sub Cmd_Delete_Clic k()
On Error GoTo Err_Cmd_Delete_ Click

Dim stn As Byte, strControl As String
strControl = Screen.Previous Control.Name
'MsgBox strControl
Application.Ech o False

DoCmd.SetWarnin gs False
DoCmd.DoMenuIte m acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuIte m acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnin gs True

Me.DrTotal = DSum("DEBIT", "JVTable") ' After deleting a Record
Totals shd be re-calculated
Me.CrTotal = DSum("CREDIT", "JVTable")

stn = Sub_Tran_No - 1 'Saving Current Record Pointer Position
Call Cmd_ReNumber_Cl ick 'Re-Number the sub_tran_no field if any
record is DELETED

Me.Recordset.Fi ndFirst "[sub_tran_no]=" & stn
If Me.Recordset.No Match Then
Me.Recordset.Mo veLast
End If
Me.Controls(str Control).SetFoc us
Application.Ech o True

Exit_Cmd_Delete _Click:
Exit Sub

Err_Cmd_Delete_ Click:
If Err.Number = 3021 Then 'user tries to delete an EOF or BOF
record
'MsgBox "No More Records To Delete !", vbOKOnly +
vbInformation, "Message... "
Me.Controls(str Control).SetFoc us
Application.Ech o True
Else
MsgBox Err.Description & " " & Err.Number
End If
Resume Exit_Cmd_Delete _Click

End Sub


Private Sub Cmd_ReNumber_Cl ick() 'Code Snippet Courtesy of Wayne
Morgan
Dim rst As DAO.Recordset, lngNumber As Long
Set rst = Me.Recordset 'Clone
'MsgBox rst.BOF & " " & rst.EOF

'If (rst.BOF And rst.EOF) Then
' 'Set rst = Me.Recordset
' rst.Requery
' Me.RecordsetClo ne.Requery
' MsgBox "RecordsetC lone is EMPTY ! REQUERYING !!"
'End If
If Not (rst.BOF And rst.EOF) Then
With rst
.MoveFirst
lngNumber = 0
Do Until .EOF
lngNumber = lngNumber + 1
.Edit
![Sub_Tran_No] = lngNumber
.Update
.MoveNext
Loop
'.Close
End With
End If
'Set rst = Nothing

If Me.Recordset.Re cordCount = 0 Then
Me.Sub_Tran_No. DefaultValue = 1
Else
Me.Sub_Tran_No. DefaultValue = DMax("sub_tran_ no", "JVTable") +
1
End If

'.............. ............... ............... ............... ............... ...........

Me.Refresh

'MsgBox "All Transactions Re-Numbered !"
End Sub
**** End of Post ****

Nov 13 '05 #18
Thx Wayne ! The moment I used Application.Ech o there was an error & my
screen went blank in a real weird manner. I had to somehow shut down
Access; Re-Start the program & realized immediately the necessity of
adding Application.Ech o on in my error handler.

So when Bas mentioned it, I smiled ... (I'd already learned the "hard"
way).

Thx for the warning too Wayne. While we're at it, do you know of any
way to sync the RecordsetCLone with the Recordset once it gets
disconnected ? I'm just curious.

Also just rcvd an email request from Sabine Oebbecke ... he's requested
if I could post my code. I'll do that right away. It'd be great if
anyone else could also benefit from this.

Best Rgds,
Prakash.

Nov 13 '05 #19
The only way I know of to "sync" the clone with the recordset once it has
become "disconnect ed" is to open a new clone. If they are "in sync" you can
move them both to the same record by setting the Bookmark of one equal to
the Bookmark of the other.

CloneRecordset. Bookmark = RealRecordset.B ookmark

--
Wayne Morgan
MS Access MVP
"Prakash" <si****@omantel .net.om> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Thx Wayne ! The moment I used Application.Ech o there was an error & my
screen went blank in a real weird manner. I had to somehow shut down
Access; Re-Start the program & realized immediately the necessity of
adding Application.Ech o on in my error handler.

So when Bas mentioned it, I smiled ... (I'd already learned the "hard"
way).

Thx for the warning too Wayne. While we're at it, do you know of any
way to sync the RecordsetCLone with the Recordset once it gets
disconnected ? I'm just curious.

Also just rcvd an email request from Sabine Oebbecke ... he's requested
if I could post my code. I'll do that right away. It'd be great if
anyone else could also benefit from this.

Best Rgds,
Prakash.

Nov 13 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1569
by: Sumanth Suri | last post by:
Hi, I want to setup one of the fields in a table so it increments sequentially(int data type). i.e the first record should be record 1 and the second one should be 2 and so on. This field will also be the key field. I am new to SQL and don't know how to do this. I am using SQL server 2000. Thanks for the help in advance. -S
5
4619
by: Charles McCaffery | last post by:
I have written a database with auto-numbering and now wish to remove alkl of my test data and set the auto-numbering back to one. How do I do this please? Charles McCaffery.
1
1913
by: Wayne Aprato | last post by:
I have a report that shows the results of a query. One of the fields is an autonumber field from the query which shows for instance: 120, 121 , 122 for 3 records. Is there a way to have another field that shows the numbering starting from 1 ie. 1, 2, 3? If the records were sorted so that the first field showed the records in the order: 121, 120, 122 then I would need the second field would show them numbered as 2, 1, 3. I would also need...
2
2313
by: Wayne Aprato | last post by:
I posted this yesterday and it seems like a moderator has thrown it in another thread. This is a totally different question to the one asked in that thread, so I'm posting it again. It is not a simple "numbering records on a report" question. It is more complex than that. I have a report that shows the results of a query. One of the fields is an autonumber field from the query which shows for instance: 120, 121 , 122 for 3 records. ...
1
1760
by: Sabine Oebbecke | last post by:
Hi there, Need some help again ... I have a continuous form which shows the attendees of a competition as per their placing in the competition. So, the first record is the winner, the second record is the 2nd place, etc. The continuous form's recordsource is an updatable query. The query/form has got a field 'place' into which the reached place is
3
2606
by: Chris | last post by:
Before I started to create table, etc to track unique form field record number assigments I thought I'd check to see if there is now a better way to do this in .NET. I have a parent form (table) and children form (table). Relationship equals one to many. I'd like to auto number the fields accordingly and traditionaly I assign a unique number based on a table value that I retrieve + 1. i.e. Parent record field value = 1 Children record...
3
5130
by: joelpollock | last post by:
I'm having trouble continuously page numbering a large report in MS Access. The report is made up of three separate Access reports which I join together at the end. In the past I have opened the reports and viewed them to see how long they are then go in and manually type the page number and total page number. I am aware of the and lines of code but this resets with each new report.
8
2758
by: jcoleshill | last post by:
Hello, I am new to Access, I'm trying to make the switch from Excel to Access as the databases I'm working with have over 200,000 records. In excel, when you want a field to autofill numbering, it's easy. You type in 1,2,3,4 etc. highlight this and drag or double click and magic the rest of the records are filled in for this field with the continued counting. How the $#^%&$%#@ does one do this in Access. I have 2003. Please Help!
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.