Form Opens In Edit Mode

ardy

Registered User.
Local time
Today, 02:10
Joined
Sep 24, 2012
Messages
98
Hello All....
I have been working on a Access(2007) applet. All is going well with an exception of not being able to open one of my forms in normal mode(not an edit mode). It seems no matter what i do the form opens in edit mode. this is with the little pencil to the left( See EM.jpg). I need to open this form in normal mode or not edit mode the solid right pointed triangle (See NM.jpg). I have tried All I know but still nothing.....:banghead:
OK I know for you to help me you need to know the the code behind the button that opens the form....so here are the codes. Also please take into account that I am not a programmer by profession, but have managed to learn a lot from you guys through the years. any help is appreciated.....

Form Data Tab States....
Data Entry = No
Allow Additions = No
Allow Deletions = No
Allow Edits = No

The Click event that opens the form.....
On Click Event:
Code:
'[FONT=Arial][SIZE=2] Open Access Agreement Information
    Dim wel As String
    Dim Agreement_ID As String
    Dim WellLookup As String
    Dim WellLookup1 As String
    Dim APN_ As String
       
   wel = Forms!Facility_Details!Well_ID
   Agreement_ID = wel & "-" & Forms!Facility_Details!ID
   APN_ = Forms!Facility_Details!APN
   ' ----------
    WellLookup = Nz(DLookup("Access_Agreement_ID", "Access_Agreement", "Access_Agreement_ID = '" & Agreement_ID & "'"))
    WellLookup1 = Nz(DLookup("ID", "Access_Agreement", "Access_Agreement_ID = '" & Agreement_ID & "'"))
  '  MsgBox "WellLookup= " & WellLookup & "WellLookup1= " & WellLookup1
    

   If Agreement_ID = WellLookup Then
        DoCmd.OpenForm "Access_Agreement", , , "ID = " & WellLookup1

   Else
        MsgBox "There is no Agreement for " & wel & vbNewLine _
        & "Creating agreement Record "
        ' MsgBox wel ' For testing
        DoCmd.OpenForm "Access_Agreement_NR", acNormal, , , acFormAdd, acWindowNormal
        Forms!Access_Agreement_NR!Access_Agreement_ID = Agreement_ID
        Forms!Access_Agreement_NR!Well_ID = wel
        Forms!Access_Agreement_NR!APN = APN_
        Exit Sub
   End If[/SIZE][/FONT]
The form once opens has 3 Evens ( On Current, On Load and On Open) The code for each is below.

On Current:
Code:
[FONT=Arial][SIZE=2]' hide copy button when mail address is null
    If Nz(Me!Mail_Address, "") = "" Then
        Me!CmdCopy.Visible = True
    Else
        Me!CmdCopy.Visible = False
    End If
        Exit Sub[/SIZE][/FONT]
On Load:
Code:
[SIZE=2][FONT=Arial]'update APN Field - Normalize empty Expire Date.
    Dim APN As String
    Dim Renwal_warning As Boolean
    Dim DontNeedAccess As String
    Dim Have_AA As Double
    Dim Need_AA As Double

        ' Lookup to see if need to renew from hist table
        Renwal_warning = DLookup("Renwal", "Access_Agreement_Hist", "[Access_Agreement_ID]='" & Forms![Access_Agreement]![Access_Agreement_ID] & "'")
        DontNeedAccess = DLookup("Need_Access", "Access_Agreement_Hist", "[Access_Agreement_ID]='" & Forms![Access_Agreement]![Access_Agreement_ID] & "'")
        ' Need agreement Logic variable assignments
        Have_AA = Me.Chk_HaveAA
        Need_AA = Me.Chk_NeedAA
'        MsgBox Have_AA & " --- " & Need_AA  ' for testing
        
        APN = Forms!Facility_Details!APN
        Me.APN = APN
        
        ' Need agreement Logic
        If Have_AA = -1 Then
            Me.Chk_NeedAA = 0
        End If
        
        ' ============================ Warning boxs messages
        If Renwal_warning = True Then
            Me.Txt_Warning.BackColor = 12695295
            Me.Txt_Warning.FontBold = True
            Me.Txt_Warning.FontSize = 11
            Me.Txt_Warning = "Need To Renew Access Agreement"
            Me.Chk_NeedAA = -1
            Me.Chk_HaveAA = 0
             Else
                Me.Txt_Warning = ""
                Me.Chk_NeedAA = 0
        End If
        
        If DontNeedAccess = "No" Then
            Me.Txt_Warning2.BackColor = 12695295
            Me.Txt_Warning2.FontBold = True
            Me.Txt_Warning2.FontSize = 11
            Me.Txt_Warning2 = "We Do Not Access This Property- No AA Needed"
             Else
                Me.Txt_Warning2 = ""
        End If
        ' ============================= End Warning messages
        
        ' chack for null date to set the other dates to null
        If IsNull(Me.Agreement_Start_Date) Then
            Me.Agreement_Expire_Date = Null
            Me.Agreement_Notice_Date = Null
                Else
        End If
            Exit Sub[/FONT][/SIZE]
On Open:
Code:
[SIZE=2][FONT=Arial]' Synching the APN.  Make sure the APN in The facility detail is the same APN in AA form
    Dim APN_AAform As Double
    
        APN_AAform = Forms!Access_Agreement.APN
' Changing facility detail APN to the same APN in AA form
        Forms!Facility_Details.APN = APN_AAform
            Exit Sub
End Sub[/FONT][/SIZE]
 

Attachments

  • EM.jpg
    EM.jpg
    2.3 KB · Views: 101
  • NM.jpg
    NM.jpg
    2.1 KB · Views: 102
If you setting values for bound controls then you are editing the record.
You can save the record if you like by setting dirty = false i.e.

DoCmd.OpenForm "form1"
Forms!form1!fld1 = "hello"
Forms!form1.Dirty = False
 
Thanks for the reply......

So I guess my confusion at this point is that do I do that in every code that set values..... and which part of the code I inset that right after I set it.......? can you show me an example in one of the codes I provided.......
 
You only need to save the record once.
You can do right at the end if you like, before 'exit sub'

Code:
        Forms!Access_Agreement_NR!APN = APN_
        Forms!Access_Agreement_NR.dirty=false
        Exit Sub
   End If


Forms are really for people to enter data into.
If you want to use code to modify data you can do it directly in the table(s).

You might also be able to set default values that your users could modify before it gets committed.

Code:
DoCmd.OpenForm "form1"
Forms!form1!fld1.DefaultValue = "='bumfluff'"
DoCmd.GoToRecord , , acNewRec
 
Thanks for the reply.......

I see the logic, I added the code, but still come up in edit mode....... I have to look at the events when I open the form more closely, I must be missing it somewhere........:banghead:
if o do a DoCmd.RunCommand acCmdSaveRecord behind a button on the form and run it it works but the same command doesn't work in the events.....

Access Agreement Form Events
On Click Event:
Code:
'[FONT=Arial][SIZE=2] Open Access Agreement Information
    Dim wel As String
    Dim Agreement_ID As String
    Dim WellLookup As String
    Dim WellLookup1 As String
    Dim APN_ As String
       
   wel = Forms!Facility_Details!Well_ID
   Agreement_ID = wel & "-" & Forms!Facility_Details!ID
   APN_ = Forms!Facility_Details!APN
   ' ----------
    WellLookup = Nz(DLookup("Access_Agreement_ID", "Access_Agreement", "Access_Agreement_ID = '" & Agreement_ID & "'"))
    WellLookup1 = Nz(DLookup("ID", "Access_Agreement", "Access_Agreement_ID = '" & Agreement_ID & "'"))
  '  MsgBox "WellLookup= " & WellLookup & "WellLookup1= " & WellLookup1
    

   If Agreement_ID = WellLookup Then
        DoCmd.OpenForm "Access_Agreement", , , "ID = " & WellLookup1

   Else
        MsgBox "There is no Agreement for " & wel & vbNewLine _
        & "Creating agreement Record "
        ' MsgBox wel ' For testing
        DoCmd.OpenForm "Access_Agreement_NR", acNormal, , , acFormAdd, acWindowNormal
        Forms!Access_Agreement_NR!Access_Agreement_ID = Agreement_ID
        Forms!Access_Agreement_NR!Well_ID = wel
        Forms!Access_Agreement_NR!APN = APN_
        Exit Sub
   End If[/SIZE][/FONT]
The form once opens has 3 Evens ( On Current, On Load and On Open) The code for each is below.

On Current:
Code:
[FONT=Arial][SIZE=2]' hide copy button when mail address is null
    If Nz(Me!Mail_Address, "") = "" Then
        Me!CmdCopy.Visible = True
    Else
        Me!CmdCopy.Visible = False
    End If
        Exit Sub[/SIZE][/FONT]
On Load:
Code:
[SIZE=2][FONT=Arial]'update APN Field - Normalize empty Expire Date.
    Dim APN As String
    Dim Renwal_warning As Boolean
    Dim DontNeedAccess As String
    Dim Have_AA As Double
    Dim Need_AA As Double

        ' Lookup to see if need to renew from hist table
        Renwal_warning = DLookup("Renwal", "Access_Agreement_Hist",  "[Access_Agreement_ID]='" &  Forms![Access_Agreement]![Access_Agreement_ID] & "'")
        DontNeedAccess = DLookup("Need_Access", "Access_Agreement_Hist",  "[Access_Agreement_ID]='" &  Forms![Access_Agreement]![Access_Agreement_ID] & "'")
        ' Need agreement Logic variable assignments
        Have_AA = Me.Chk_HaveAA
        Need_AA = Me.Chk_NeedAA
'        MsgBox Have_AA & " --- " & Need_AA  ' for testing
        
        APN = Forms!Facility_Details!APN
        Me.APN = APN
        
        ' Need agreement Logic
        If Have_AA = -1 Then
            Me.Chk_NeedAA = 0
        End If
        
        ' ============================ Warning boxs messages
        If Renwal_warning = True Then
            Me.Txt_Warning.BackColor = 12695295
            Me.Txt_Warning.FontBold = True
            Me.Txt_Warning.FontSize = 11
            Me.Txt_Warning = "Need To Renew Access Agreement"
            Me.Chk_NeedAA = -1
            Me.Chk_HaveAA = 0
             Else
                Me.Txt_Warning = ""
                Me.Chk_NeedAA = 0
        End If
        
        If DontNeedAccess = "No" Then
            Me.Txt_Warning2.BackColor = 12695295
            Me.Txt_Warning2.FontBold = True
            Me.Txt_Warning2.FontSize = 11
            Me.Txt_Warning2 = "We Do Not Access This Property- No AA Needed"
             Else
                Me.Txt_Warning2 = ""
        End If
        ' ============================= End Warning messages
        
        ' chack for null date to set the other dates to null
        If IsNull(Me.Agreement_Start_Date) Then
            Me.Agreement_Expire_Date = Null
            Me.Agreement_Notice_Date = Null
                Else
        End If
            Exit Sub[/FONT][/SIZE]
On Open:
Code:
[SIZE=2][FONT=Arial]' Synching the APN.  Make sure the APN in The facility detail is the same APN in AA form
    Dim APN_AAform As Double
    
        APN_AAform = Forms!Access_Agreement.APN
' Changing facility detail APN to the same APN in AA form
        Forms!Facility_Details.APN = APN_AAform
            Exit Sub
End Sub[/FONT][/SIZE]
 
Last edited:
Hmmmm.

I just searched this page for dirty and the only matches were in my own posts...

Forgive me, but I'm not reading through your code for you.
 
Solved. I needed to place the code in couple other places........
Code:
Forms!Access_Agreement.Dirty = False
Thanks:)
 
Last edited:
Static,
Do appreciate your help. sometimes when you look at the same code day after day things become fuzzy, The purpose for the code placement was that sometimes when a fresh set of eyes looks at it they might just might see something that is obvious.

You have helped me greatly and no forgiveness is necessary. All and all I really am thankful to you and all who have helped me int his forum......
 
Solved. I needed to place the code in couple other places........
Code:
Forms!Access_Agreement.Dirty = False

Thanks:)
I don't think it matters but you should only need the code once. If you step through the code at run time you will be able to determine in which event that happens for the last time.
 

Users who are viewing this thread

Back
Top Bottom