Link to home
Start Free TrialLog in
Avatar of linder76
linder76

asked on

Access VBA - Using Allowedits

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?
SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of linder76
linder76

ASKER

The save code is basically uploading the data to the web then:
docmd.save
me.allowedits = false
"docmd.save" does not save the record, it saves the form design.
Use
 me.dirty = false



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
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
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
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)

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

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.