Solved

Access VBA - Using Allowedits

Posted on 2009-04-14
11
760 Views
Last Modified: 2012-06-27
I have a form where the user can press the edit button and will allow the user to edit the curretn record.

The user needs to press SAVE to save the changes. At that time in the code allowedits is set back to False BUT the records are still editable.

Can anybody help?
0
Comment
Question by:linder76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 150 total points
ID: 24140107
dont know if redrawing the screen helps here eg  me.repaint  I would of thought it would be affected straight away though
have u disabled adds also?


when saving, how do you do it. do u have your own code? eg if me.dirty then me.dirty = false

0
 
LVL 77

Accepted Solution

by:
peter57r earned 175 total points
ID: 24140112
Please post the 'Save' code.
0
 
LVL 15

Assisted Solution

by:MNelson831
MNelson831 earned 175 total points
ID: 24140138
Create this function and then call it before and after the record is edited and saved:

Public Function fnLockControls(stFormName As String, ynState As Boolean)
On Error Resume Next

Dim oControl As Object

For Each oControl In Forms(stFormName).Controls
         'Loop through the controls and set the value of the locked property
         Forms(stDocName).Controls(oControl.Name).Locked = ynState
      Next

End Function


Call the function like this to lock controls on the current form:

fnLockControls(Me.Name, True)

To unlock on the current form:

fnLockControls(Me.Name, False)

To lock on a different form:

fnLockControls("SomeOtherFormname", True)

To unlock on a different form:

fnLockControls("SomeOtherFormName",False)
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:linder76
ID: 24140152
The save code is basically uploading the data to the web then:
docmd.save
me.allowedits = false
0
 
LVL 77

Expert Comment

by:peter57r
ID: 24140235
"docmd.save" does not save the record, it saves the form design.
Use
 me.dirty = false



0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24140272
ah, nice food, just had my supper!

linder76, to do a save, use dirty like I showed in my first post. Pete has also shown you to use that. Me.dirty is true if changes have been made to the form, Me.Dirty = false forces a save
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24140358
right, back again

Im wondering if you disable adds and then set DataEntry to No

at what stage do you allow editing? Do you toggle between editing and non editing? DataEntry will cause an issue otherwise
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24140375
ok, just did a test. Created two buttons to see what affect DataEntry has, none really. It was set to False but still allows editing when AllowEdits switched on
0
 
LVL 15

Expert Comment

by:MNelson831
ID: 24140430
Alternately, you could lock each control manually and individually:

With me
     .MyControlName1.locked = true
     .MyControlName2.locked = true
     .MyControlName3.locked = true
     .MyControlName4.locked = true
End with


Or you could add the specific control name to the function above:

Public Function fnLockControls(stFormName As String, stControlName as string, ynState As Boolean)

Forms(stFormName).Controls(stControlName).Locked = ynState

End Function



And then call it for each control:

fnLockControl(Me.Name, MyControlName, True)

0
 

Author Comment

by:linder76
ID: 24140698
Sorry here is the complete code....I type the wrong save function it shows the real one
I made a button where once it clicked on with turn off allow edits but here in the code the allow edits isnt' working. I hope this helps.

Dim cnMyCompany As ADODB.Connection
Dim rs_tblCM_WP_WEB As ADODB.Recordset
Dim rs_tblCM_WP As Recordset
Dim IntRecordCount As Integer, I As Integer
Dim DB As Database
    
Set DB = CurrentDb
Set cnABOMS = New ADODB.Connection
Set rs_tblCM_WP = DB.OpenRecordset("tbl_CM_WP")
 
On Error GoTo Err_cmdUpload_Click
 
DoCmd.Hourglass True
 
With cnMyCompany
.ConnectionString = "Provider=MSDataShape.1;Persist Security Info=True;Data Source=""& _
"User ID="";Password="";Initial Catalog="";Data Provider=SQLOLEDB.1"
.ConnectionTimeout = 10
.Open
End With
 
    Set rs_tblCM_WP_WEB = New ADODB.Recordset
    
        With rs_tblCM_WP_WEB
        .CursorType = adOpenDynamic
        .CursorLocation = adUseClient
        .LockType = adLockOptimistic
        .Open "tbl_CM_WP", cnMyCompany
    
    End With
    
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    
    
   rs_tblCM_WP_WEB!COMST_OpenDate = rs_tblCM_WP!COMST_OpenDate
   rs_tblCM_WP_WEB!COMST_CloseDate = rs_tblCM_WP!COMST_CloseDate
   rs_tblCM_WP_WEB!COMST_Fee = rs_tblCM_WP!COMST_Fee
   rs_tblCM_WP_WEB!COMST_Year = rs_tblCM_WP!COMST_Year
            
       rs_tblCM_WP_WEB!Recert_App_OpenDate = rs_tblCM_WP!Recert_App_OpenDate
       rs_tblCM_WP_WEB!Recert_App_CloseDate = rs_tblCM_WP!Recert_App_CloseDate
       rs_tblCM_WP_WEB!Recert_App_Fee = rs_tblCM_WP!Recert_App_Fee
    
           rs_tblCM_WP_WEB!Recert_Schedule_OpenDate = rs_tblCM_WP!Recert_Schedule_OpenDate
           rs_tblCM_WP_WEB!Recert_Schedule_CloseDate = rs_tblCM_WP!Recert_Schedule_CloseDate
    
   rs_tblCM_WP_WEB!Recert_Exam_OpenDate = rs_tblCM_WP!Recert_Exam_OpenDate
   rs_tblCM_WP_WEB!Recert_Exam_CloseDate = rs_tblCM_WP!Recert_Exam_CloseDate
 
   rs_tblCM_WP_WEB.Update
                    
    Me.txt_Updated.Value = Now()
 
  Me.AllowEdits = False*******here is where I put the allowedit back to false
 
    Me.Refresh
    
    Me.lblEdit.Visible = False
 
 
 
    DoEvents
 
 
MsgBox "Parameters Uploaded", vbExclamation, "CM Parameters Uploaded"
 
Me.cmdClose.SetFocus
 
 
DoCmd.Hourglass False
 
intStop = False
 
Exit_cmdUpload_Click:
    Exit Sub
 
Err_cmdUpload_Click:
    MsgBox Err.Description
    Resume Exit_cmdUpload_Click
End Sub

Open in new window

0
 

Author Comment

by:linder76
ID: 24140890
You guys gave me an idea .... I put in the code me.dataentry = false then the me.allowedits=false...and it worked but another error has occurred whihc I need help on but will post that later in a new question.
So Thanks for your hard work...am going to split the points.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question