X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Edit Mode vs Add Mode    
 
   
TKnyte
post Jun 4 2010, 02:33 PM
Post #1

UtterAccess Member
Posts: 28
From: Oregon



So I do realize that it's limited, but I'm using the switchboard for my database and I have a form that I use for adding or editing patient info (I work at a hospital). The switchboard uses a macro to open the form using an argument to determine if it's opened in "Add Mode", "Edit Mode", or "Read Only" mode. For my purposes I only need the first 2. I've created a button on the form that effectively switches between "Add Mode" and "Edit Mode". Basically it just modifies a few of the form properties (Data Entry, Allow Additions, Allow Deletions, Allow Edits), and toggles the visibility of a few buttons and a combo box that is only needed in one mode or the other.
o on the switchboard I have one button that is supposed to open the form in "Add Mode" and I have a second button that is supposed to open the form in "Edit Mode". What I'm hoping for is that on form load I could have it detect what "mode" the form is in and then set the visibilities and such to match with the proper mode. So far though I'm having issues figuring out how to do this properly. Right now I have an If, Then, Else statement, but I'm unsure of what property I should be testing. I've tried using
CODE
If Me.Form.DataEntry = True Then
        btnSwitchEdit_Click
    Else
        btnSwitchAdd_Click
    End If

but apparently me.form.dataentry is not the right thing to test as it always opens in the same mode no matter which selection I choose on the switchboard. I'm sure I'm just missing something simple, but I've been banging my head on this for a full day now...
Go to the top of the page
 
+
drew1373
post Jun 4 2010, 02:43 PM
Post #2

UtterAccess Enthusiast
Posts: 67
From: Erie, PA, USA



Hi TKNyte,
e.Form.DataEntry would be referring to the Switchboard.
You should try Forms(OpenedFormName).DataEntry and it should work
Go to the top of the page
 
+
TKnyte
post Jun 4 2010, 04:43 PM
Post #3

UtterAccess Member
Posts: 28
From: Oregon



I tried changing me.form.dataentry to Forms!frmCases.dataentry, but that didn't work. Am I missing something?
I'm a little confused on the part about me.form.dataentry referring to the switchboard. That if statement is in the form_load() event for frmCases (the form I'm trying to open in different modes). I guess I assumed that "me" would refer to the form that the event is located in.
Go to the top of the page
 
+
theDBguy
post Jun 4 2010, 04:48 PM
Post #4

Access Wiki and Forums Moderator
Posts: 59,432
From: SoCal, USA



Hi TKnyte,
welcome2UA.gif
You are correct in assuming that "Me" will refer to the "current" (active) object. However, I am not certain that by using code such as:
DoCmd.OpenForm "frmCases", , , , acFormAdd
will actually change the status of the Data Entry property of the form to True. Which is probably why your OnLoad code is not working.
Just my 2 cents...
Go to the top of the page
 
+
TKnyte
post Jun 4 2010, 04:51 PM
Post #5

UtterAccess Member
Posts: 28
From: Oregon



That's kind of what I was wondering myself. I've tested out the If statement (with "If 1=1 then..." and "If 1=2 then...") just to make sure the rest of the code worked fine and it does, I'm just looking for what I need to test. It seems to me that there should be something I can use to test for what mode it has been opened in. :-/
Go to the top of the page
 
+
theDBguy
post Jun 4 2010, 04:56 PM
Post #6

Access Wiki and Forums Moderator
Posts: 59,432
From: SoCal, USA



Hi TKNyte,
just did some testing and found out that if you move your code to the Form's Open event, it should work.
Hope that helps...
Go to the top of the page
 
+
TKnyte
post Jun 10 2010, 12:53 PM
Post #7

UtterAccess Member
Posts: 28
From: Oregon



Hey DBGuy, I moved the code to the "On Open" event, but I still can't seem to get the if statement to trigger. I've tried
!--c1-->
CODE
If Me.Form.DataEntry = True Then...

and I've tried
CODE
If Forms![FormName].DataEntry = True Then...

Am I testing the wrong thing?
Go to the top of the page
 
+
BananaRepublic
post Jun 10 2010, 01:01 PM
Post #8

Admin under the bridge
Posts: 1,210
From: Banana Republic



It's been a long while but I remember running in a situation where I found that the EditMode argument isn't exactly equilvalent to setting the relevant properties manually. My memory says that opening a form in a Edit mode allows new records to be added even if it was intended that only existing records should be edited. For that reason, I decided to avoid the ambiguity of using EditMode and instead pass in a OpenArgs that specified what mode it should be in and let the Load or Open event handle it accordingly.
Go to the top of the page
 
+
TKnyte
post Jun 10 2010, 01:17 PM
Post #9

UtterAccess Member
Posts: 28
From: Oregon



That makes sense. I think I'll just skip the whole "If" part and just put code in the two different buttons opening the form to set the appropriate properties.
Go to the top of the page
 
+
theDBguy
post Jun 10 2010, 03:57 PM
Post #10

Access Wiki and Forums Moderator
Posts: 59,432
From: SoCal, USA



Hi,
See if the attached demo makes sense.
Hope that helps...
Attached File(s)
Attached File  theDBguyDataEntryDemo.zip ( 15.64K ) Number of downloads: 35
 
Go to the top of the page
 
+
TKnyte
post Jun 10 2010, 04:23 PM
Post #11

UtterAccess Member
Posts: 28
From: Oregon



Thanks a ton DBguy! That helped a lot. It was almost exactly the code and setup I had used initially. I found my problem was that apparently at some point I had manually changed the data entry property for the form to Yes. Once your working demo form showed me that my code wasn't off I got to thinking maybe something else was over riding the setting. Once I changed the data entry property to No everything worked perfect. I don't know why the initial setting of the property should mess it all up, but I'm glad it's figured out. Thanks again. <
Go to the top of the page
 
+
theDBguy
post Jun 10 2010, 04:31 PM
Post #12

Access Wiki and Forums Moderator
Posts: 59,432
From: SoCal, USA



Glad to hear you got yours to work. Good luck with your project.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Search  ·  Go to Top  ·  Lo-Fi Version Time is now: 22nd December 2014 - 05:42 PM