A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Same form for new/edit record problem



 
 
Thread Tools Display Modes
  #1  
Old May 18th, 2010, 11:30 AM posted to microsoft.public.access
PsyberFox
external usenet poster
 
Posts: 88
Default Same form for new/edit record problem

Hi there,

I have a form which has a load event to get the dmax(UserID)+5 to populate
the UserID with the new code. However, I want to use this same form to edit
existing records. When u user double-clicks on another sub-form's UserID
field, it should open the same "edit users" form as stated first, but this
time obviously with the selected record's information. The problem is that
the form's load event gets the new code, and therefore don't allow for
editing of records. How can I do both with the same form?

Thank you kindly!

--
The Psyber Fox
http://www.psyberconsulting.co.za
  #2  
Old May 18th, 2010, 12:44 PM posted to microsoft.public.access
Allen Browne
external usenet poster
 
Posts: 11,706
Default Same form for new/edit record problem

Move the code from the form's Load event into its BeforeInsert event.

The text box will populate when the user starts entering data at a new
record.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"PsyberFox" wrote in message
...
Hi there,

I have a form which has a load event to get the dmax(UserID)+5 to populate
the UserID with the new code. However, I want to use this same form to
edit
existing records. When u user double-clicks on another sub-form's UserID
field, it should open the same "edit users" form as stated first, but this
time obviously with the selected record's information. The problem is that
the form's load event gets the new code, and therefore don't allow for
editing of records. How can I do both with the same form?


  #3  
Old May 18th, 2010, 01:52 PM posted to microsoft.public.access
PsyberFox
external usenet poster
 
Posts: 88
Default Same form for new/edit record problem

Hi and thank you for the reply.

I'm still not getting it right. Herewith some code that i'm trying to run:

This one is on the edit-form after the user selected New from another
sub-form:
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim GetUserID As String
Dim NextUserID As String
GetUserID = DMax("UserID", "tbl_XUsers")
NextUserID = "U" & Format(Val(Mid(GetUserID, 2)) + 5, "0000")
[UserID].Value = NextUserID
UserName.SetFocus
End Sub

This one is the one that runs when the user has double-clicked the userID on
the aforementioned sub-form:
Private Sub UserID_DblClick(Cancel As Integer)
DoCmd.Close
DoCmd.OpenForm "frm_Users_Edit", acNormal, , "UserID=" & UserID
End Sub

After the changes you have suggested, it now comes up with a blank UserID
whether I'm selecting new / edit...


--
The Psyber Fox
http://www.psyberconsulting.co.za


"Allen Browne" wrote:

Move the code from the form's Load event into its BeforeInsert event.

The text box will populate when the user starts entering data at a new
record.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"PsyberFox" wrote in message
...
Hi there,

I have a form which has a load event to get the dmax(UserID)+5 to populate
the UserID with the new code. However, I want to use this same form to
edit
existing records. When u user double-clicks on another sub-form's UserID
field, it should open the same "edit users" form as stated first, but this
time obviously with the selected record's information. The problem is that
the form's load event gets the new code, and therefore don't allow for
editing of records. How can I do both with the same form?


.

  #4  
Old May 18th, 2010, 08:54 PM posted to microsoft.public.access
PsyberFox
external usenet poster
 
Posts: 88
Default Same form for new/edit record problem

I did come right, thank you though!
W
--
The Psyber Fox
http://www.psyberconsulting.co.za


"Allen Browne" wrote:

Move the code from the form's Load event into its BeforeInsert event.

The text box will populate when the user starts entering data at a new
record.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"PsyberFox" wrote in message
...
Hi there,

I have a form which has a load event to get the dmax(UserID)+5 to populate
the UserID with the new code. However, I want to use this same form to
edit
existing records. When u user double-clicks on another sub-form's UserID
field, it should open the same "edit users" form as stated first, but this
time obviously with the selected record's information. The problem is that
the form's load event gets the new code, and therefore don't allow for
editing of records. How can I do both with the same form?


.

  #5  
Old May 20th, 2010, 04:40 AM posted to microsoft.public.access
Allen Browne
external usenet poster
 
Posts: 11,706
Default Same form for new/edit record problem

This message is dated earlier than the one that says you have it sorted, but
showed up later.

Can you confirm if you still need help with this?

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"PsyberFox" wrote in message
...
Hi and thank you for the reply.

I'm still not getting it right. Herewith some code that i'm trying to run:

This one is on the edit-form after the user selected New from another
sub-form:
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim GetUserID As String
Dim NextUserID As String
GetUserID = DMax("UserID", "tbl_XUsers")
NextUserID = "U" & Format(Val(Mid(GetUserID, 2)) + 5, "0000")
[UserID].Value = NextUserID
UserName.SetFocus
End Sub

This one is the one that runs when the user has double-clicked the userID
on
the aforementioned sub-form:
Private Sub UserID_DblClick(Cancel As Integer)
DoCmd.Close
DoCmd.OpenForm "frm_Users_Edit", acNormal, , "UserID=" & UserID
End Sub

After the changes you have suggested, it now comes up with a blank UserID
whether I'm selecting new / edit...


--
The Psyber Fox
http://www.psyberconsulting.co.za


"Allen Browne" wrote:

Move the code from the form's Load event into its BeforeInsert event.

The text box will populate when the user starts entering data at a new
record.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"PsyberFox" wrote in message
...
Hi there,

I have a form which has a load event to get the dmax(UserID)+5 to
populate
the UserID with the new code. However, I want to use this same form to
edit
existing records. When u user double-clicks on another sub-form's
UserID
field, it should open the same "edit users" form as stated first, but
this
time obviously with the selected record's information. The problem is
that
the form's load event gets the new code, and therefore don't allow for
editing of records. How can I do both with the same form?


.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.