473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Interesting Problem...

I have a field that auto increments a number for each record. 0001,
0002 and so on. I also have two buttons on the form. One button is used
to "save" the record after all fields are entered. After a record is
saved and the user moves onto a new record all the fields in the
previous record become locked to prevent accidental/or malicious
deletion/editing of fields. If something needs to be changed I have an
Edit button which temporarily unlocks all fields. At this point the
user makes changes, and then clicks the same button which locks the
fields again. Problem is my auto increment number which is like an
invoice number will increment. Is there any way to stop this from
happening, like lock that field out permenently or something???

This is the code for the auto incrementing number:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me!displayedRunNumber = Format(CLng(Nz(DMax("displayedRunNumber",
"fields"), "0")) + 1, "0000")

End Sub

This is the code for the save button:

Private Sub saveRecord_Click()
On Error GoTo Err_saveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

Exit_saveRecord_Click:
Exit Sub

Err_saveRecord_Click:
MsgBox Err.Description
Resume Exit_saveRecord_Click

End Sub

This is the code for the "edit" unlock/relock fields button:

Private Sub editRun_Click()

If Me.EditRun.Caption = "Edit Run" Then
With Me
.AllowAdditions = True
.AllowEdits = True
.AllowDeletions = True
.EditRun.Caption = "Save Changes"
End With

Else
DoCmd.RunCommand acCmdSaveRecord
With Me
.AllowAdditions = False
.AllowEdits = False
.AllowDeletions = False
.EditRun.Caption = "Edit Run"
End With

End If

End Sub

So basically, whenever a past record is edited and resaved the
displayedRunNumber increments and I need that to stop.

Thanks in advance,

Brad G.

Aug 1 '06 #1
7 1541
On 31 Jul 2006 21:48:17 -0700, br***********@gmail.com wrote:

Yes.
If Me.NewRecord then
'get a new ID
end if

Consider using BeforeInsert.

-Tom.

>I have a field that auto increments a number for each record. 0001,
0002 and so on. I also have two buttons on the form. One button is used
to "save" the record after all fields are entered. After a record is
saved and the user moves onto a new record all the fields in the
previous record become locked to prevent accidental/or malicious
deletion/editing of fields. If something needs to be changed I have an
Edit button which temporarily unlocks all fields. At this point the
user makes changes, and then clicks the same button which locks the
fields again. Problem is my auto increment number which is like an
invoice number will increment. Is there any way to stop this from
happening, like lock that field out permenently or something???

This is the code for the auto incrementing number:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me!displayedRunNumber = Format(CLng(Nz(DMax("displayedRunNumber",
"fields"), "0")) + 1, "0000")

End Sub

This is the code for the save button:

Private Sub saveRecord_Click()
On Error GoTo Err_saveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

Exit_saveRecord_Click:
Exit Sub

Err_saveRecord_Click:
MsgBox Err.Description
Resume Exit_saveRecord_Click

End Sub

This is the code for the "edit" unlock/relock fields button:

Private Sub editRun_Click()

If Me.EditRun.Caption = "Edit Run" Then
With Me
.AllowAdditions = True
.AllowEdits = True
.AllowDeletions = True
.EditRun.Caption = "Save Changes"
End With

Else
DoCmd.RunCommand acCmdSaveRecord
With Me
.AllowAdditions = False
.AllowEdits = False
.AllowDeletions = False
.EditRun.Caption = "Edit Run"
End With

End If

End Sub

So basically, whenever a past record is edited and resaved the
displayedRunNumber increments and I need that to stop.

Thanks in advance,

Brad G.
Aug 1 '06 #2
not very... your code is in the wrong event. It should be in the
Before_INSERT, not the BeforeUpdate event. once the record has been
added to the table (inserted), it *already* has an ID number, so
there's no need to assign a new one.

Aug 1 '06 #3
Ha.. What you said sounds good.. but I have no idea how to do what your
suggesting.. any ideas... Thanks
Tom van Stiphout wrote:
On 31 Jul 2006 21:48:17 -0700, br***********@gmail.com wrote:

Yes.
If Me.NewRecord then
'get a new ID
end if

Consider using BeforeInsert.

-Tom.

I have a field that auto increments a number for each record. 0001,
0002 and so on. I also have two buttons on the form. One button is used
to "save" the record after all fields are entered. After a record is
saved and the user moves onto a new record all the fields in the
previous record become locked to prevent accidental/or malicious
deletion/editing of fields. If something needs to be changed I have an
Edit button which temporarily unlocks all fields. At this point the
user makes changes, and then clicks the same button which locks the
fields again. Problem is my auto increment number which is like an
invoice number will increment. Is there any way to stop this from
happening, like lock that field out permenently or something???

This is the code for the auto incrementing number:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me!displayedRunNumber = Format(CLng(Nz(DMax("displayedRunNumber",
"fields"), "0")) + 1, "0000")

End Sub

This is the code for the save button:

Private Sub saveRecord_Click()
On Error GoTo Err_saveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

Exit_saveRecord_Click:
Exit Sub

Err_saveRecord_Click:
MsgBox Err.Description
Resume Exit_saveRecord_Click

End Sub

This is the code for the "edit" unlock/relock fields button:

Private Sub editRun_Click()

If Me.EditRun.Caption = "Edit Run" Then
With Me
.AllowAdditions = True
.AllowEdits = True
.AllowDeletions = True
.EditRun.Caption = "Save Changes"
End With

Else
DoCmd.RunCommand acCmdSaveRecord
With Me
.AllowAdditions = False
.AllowEdits = False
.AllowDeletions = False
.EditRun.Caption = "Edit Run"
End With

End If

End Sub

So basically, whenever a past record is edited and resaved the
displayedRunNumber increments and I need that to stop.

Thanks in advance,

Brad G.
Aug 1 '06 #4
Actually I understood your If statement solution, such an easy fix
thank you..

In regards to the before insert... I like it in beforeupdate that way
my users are forced to fill in ALL the required fields before getting
the Run Number. Basically once they have a Run Number their off the
hook so it forces them to type in all the info before getting that
number.

Make sense or am I still off?
brad.goldb...@gmail.com wrote:
Ha.. What you said sounds good.. but I have no idea how to do what your
suggesting.. any ideas... Thanks
Tom van Stiphout wrote:
On 31 Jul 2006 21:48:17 -0700, br***********@gmail.com wrote:

Yes.
If Me.NewRecord then
'get a new ID
end if

Consider using BeforeInsert.

-Tom.

>I have a field that auto increments a number for each record. 0001,
>0002 and so on. I also have two buttons on the form. One button is used
>to "save" the record after all fields are entered. After a record is
>saved and the user moves onto a new record all the fields in the
>previous record become locked to prevent accidental/or malicious
>deletion/editing of fields. If something needs to be changed I have an
>Edit button which temporarily unlocks all fields. At this point the
>user makes changes, and then clicks the same button which locks the
>fields again. Problem is my auto increment number which is like an
>invoice number will increment. Is there any way to stop this from
>happening, like lock that field out permenently or something???
>
>This is the code for the auto incrementing number:
>
>Private Sub Form_BeforeUpdate(Cancel As Integer)
>
>Me!displayedRunNumber = Format(CLng(Nz(DMax("displayedRunNumber",
>"fields"), "0")) + 1, "0000")
>
>End Sub
>
>This is the code for the save button:
>
>Private Sub saveRecord_Click()
>On Error GoTo Err_saveRecord_Click
>
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
>acMenuVer70
>
>Exit_saveRecord_Click:
Exit Sub
>
>Err_saveRecord_Click:
MsgBox Err.Description
Resume Exit_saveRecord_Click
>
>End Sub
>
>This is the code for the "edit" unlock/relock fields button:
>
>Private Sub editRun_Click()
>
>If Me.EditRun.Caption = "Edit Run" Then
With Me
.AllowAdditions = True
.AllowEdits = True
.AllowDeletions = True
.EditRun.Caption = "Save Changes"
End With
>
>Else
DoCmd.RunCommand acCmdSaveRecord
With Me
.AllowAdditions = False
.AllowEdits = False
.AllowDeletions = False
.EditRun.Caption = "Edit Run"
End With
>
>End If
>
>End Sub
>
>So basically, whenever a past record is edited and resaved the
>displayedRunNumber increments and I need that to stop.
>
>Thanks in advance,
>
>Brad G.
Aug 1 '06 #5
"br***********@gmail.com" <br***********@gmail.comwrote in message
<11**********************@i3g2000cwc.googlegroups. com>:
I have a field that auto increments a number for each record. 0001,
0002 and so on. I also have two buttons on the form. One button is
used to "save" the record after all fields are entered. After a
record is saved and the user moves onto a new record all the fields
in the previous record become locked to prevent accidental/or
malicious deletion/editing of fields. If something needs to be
changed I have an Edit button which temporarily unlocks all fields.
At this point the user makes changes, and then clicks the same button
which locks the fields again. Problem is my auto increment number
which is like an invoice number will increment. Is there any way to
stop this from happening, like lock that field out permenently or
something???

This is the code for the auto incrementing number:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Me!displayedRunNumber = Format(CLng(Nz(DMax("displayedRunNumber",
"fields"), "0")) + 1, "0000")

End Sub

This is the code for the save button:

Private Sub saveRecord_Click()
On Error GoTo Err_saveRecord_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

Exit_saveRecord_Click:
Exit Sub

Err_saveRecord_Click:
MsgBox Err.Description
Resume Exit_saveRecord_Click

End Sub

This is the code for the "edit" unlock/relock fields button:

Private Sub editRun_Click()

If Me.EditRun.Caption = "Edit Run" Then
With Me
.AllowAdditions = True
.AllowEdits = True
.AllowDeletions = True
.EditRun.Caption = "Save Changes"
End With

Else
DoCmd.RunCommand acCmdSaveRecord
With Me
.AllowAdditions = False
.AllowEdits = False
.AllowDeletions = False
.EditRun.Caption = "Edit Run"
End With

End If

End Sub

So basically, whenever a past record is edited and resaved the
displayedRunNumber increments and I need that to stop.

Thanks in advance,

Brad G.
Restrict the updating of this control to when there's a new record

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.NewRecord Then
Me!displayedRunNumber =
Format(CLng(Nz(DMax("displayedRunNumber", "fields"), "0")) + 1, "0000")
End If
End Sub

--
Roy-Vidar
Aug 1 '06 #6
Actually I understood your If statement solution, such an easy fix
thank you..

In regards to the before insert... I like it in beforeupdate that way
my users are forced to fill in ALL the required fields before getting
the Run Number. Basically once they have a Run Number their off the
hook so it forces them to type in all the info before getting that
number.

Make sense or am I still off?
brad.goldb...@gmail.com wrote:
Ha.. What you said sounds good.. but I have no idea how to do what your
suggesting.. any ideas... Thanks
Tom van Stiphout wrote:
On 31 Jul 2006 21:48:17 -0700, br***********@gmail.com wrote:

Yes.
If Me.NewRecord then
'get a new ID
end if

Consider using BeforeInsert.

-Tom.

>I have a field that auto increments a number for each record. 0001,
>0002 and so on. I also have two buttons on the form. One button is used
>to "save" the record after all fields are entered. After a record is
>saved and the user moves onto a new record all the fields in the
>previous record become locked to prevent accidental/or malicious
>deletion/editing of fields. If something needs to be changed I have an
>Edit button which temporarily unlocks all fields. At this point the
>user makes changes, and then clicks the same button which locks the
>fields again. Problem is my auto increment number which is like an
>invoice number will increment. Is there any way to stop this from
>happening, like lock that field out permenently or something???
>
>This is the code for the auto incrementing number:
>
>Private Sub Form_BeforeUpdate(Cancel As Integer)
>
>Me!displayedRunNumber = Format(CLng(Nz(DMax("displayedRunNumber",
>"fields"), "0")) + 1, "0000")
>
>End Sub
>
>This is the code for the save button:
>
>Private Sub saveRecord_Click()
>On Error GoTo Err_saveRecord_Click
>
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
>acMenuVer70
>
>Exit_saveRecord_Click:
Exit Sub
>
>Err_saveRecord_Click:
MsgBox Err.Description
Resume Exit_saveRecord_Click
>
>End Sub
>
>This is the code for the "edit" unlock/relock fields button:
>
>Private Sub editRun_Click()
>
>If Me.EditRun.Caption = "Edit Run" Then
With Me
.AllowAdditions = True
.AllowEdits = True
.AllowDeletions = True
.EditRun.Caption = "Save Changes"
End With
>
>Else
DoCmd.RunCommand acCmdSaveRecord
With Me
.AllowAdditions = False
.AllowEdits = False
.AllowDeletions = False
.EditRun.Caption = "Edit Run"
End With
>
>End If
>
>End Sub
>
>So basically, whenever a past record is edited and resaved the
>displayedRunNumber increments and I need that to stop.
>
>Thanks in advance,
>
>Brad G.
Aug 1 '06 #7
pi********@hotmail.com wrote:
not very... your code is in the wrong event. It should be in the
Before_INSERT, not the BeforeUpdate event. once the record has been
added to the table (inserted), it *already* has an ID number, so
there's no need to assign a new one.
The problem with BeforeInsert is that it won't work reliably in a multi-user
environment. In addition, there are cases where you can create a new record and
save it without BeforeInsert ever firing.

As long as you test for NewRecord BeforeUpdate is the best event for this
because it is the only event that ends with the record being saved.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Aug 1 '06 #8

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

Similar topics

56
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
23
by: Bruno R. Dias | last post by:
Perhaps it would be interesting to program a virtual machine simulating an ancient computer (such as the pdp-7). Then, it would be rather interesting to code for it (porting gcc to it maybe?). I...
7
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate...
1
by: Rakesh Roberts | last post by:
I think I have a very interesting cookie problem. I use form authentications on my application. Through out my application I started using a toggle control that persists its value for the session...
2
by: sasifiqbal | last post by:
Hi, One of my developers are facing an interesting problem regarding UserControl invalidation. The problem is: We have two forms in our application. Form A does nothing except loading of...
27
by: Frederick Gotham | last post by:
I thought it might be interesting to share experiences of tracking down a subtle or mysterious bug. I myself haven't much experience with tracking down bugs, but there's one in particular which...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
5
by: Will Honea | last post by:
I've hit an interesting trap trying to migrate data off an OS/2 server running version 7.2 (fp14) over to 8.2 on Linux. Seems that one table has a column defined in the DDL as "BIGINT NOT NULL...
11
by: onkar.n.mahajan | last post by:
Is it possible to from function call on fly in C programming language ? I am faced with an interesting problem in that I need to take function name and arguments on fly (actually from Database...
4
by: Andrew | last post by:
I am having an interesting namespace conflict. When we use a third party lib we create a company assembly for any descending classes to go in. I have simplified the problem into the example...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.