Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms not editable

Status
Not open for further replies.

Costefran

Technical User
Jan 2, 2008
197
GB
This is driving me insane so if anyone can help that would be great

I have a form which I open in acedit mode which then based on the record and user logged in I have a Dlookup which sets the value of an unbound control. The value of this control then determines if the record is editable or not but it doesn't work as the record is still not updatable

The code below is in the form's current section


'this sets the unbound control on my form to either 1 or 0
The record is editable as the unbound control is set to 1
Me.Edit_or_Read_Only = 1
'if [Building] is not "TBA" then the record may be editable as the unbound control is set to 1 or 0 depending on record and user name
'The above element of the code works fine
If [Forms]![Work Input Form]![Building] <> "TBA" Then Me.Edit_or_Read_Only = DLookup("[Count]", "Work Input Form Edit or Read Only Q3", "")
If Me.Edit_or_Read_Only = 1 Then Me.Read_Only_Title_Bar = "This Record is Editable"
If Me.Edit_or_Read_Only = 0 Then Me.Read_Only_Title_Bar = "This Record is Read Only"
If Me.Edit_or_Read_Only = 1 Then Me.Form.AllowEdits = True

Note - when I open up the form to add a new record it works fine
 
I never write my If Then statements in one line. I think this makes it harder to read and understand. I see where your code sets your form to AllowEdits = True but not AllowEdits = False.


Duane
Hook'D on Access
MS Access MVP
 
How are ya Costefran . . .

Your biggest problem is with the [blue]DLookup[/blue] aggregate function.
Microsoft said:
[blue] ... if you don't supply a value for criteria, the DLookup function [purple]returns a [red]random[/red] value in the domain.[/purple][/blue]
Additionally, if DLookup finds no records in the domain, a [blue] Null[/blue] is returned ... not a zero. This can be fixed with the [blue]Nz()[/blue] function.

Now ... I'm not sure of your intent with DLookup other than to [blue]return the count value[/blue] of some record in [blue]Work Input Form Edit or Read Only Q3[/blue] (you'll have to spean on this). Note that since your code is suppose to take care of edit or read only ... you don't need [blue]acEdit[blue]. The following is what I believe you should have until you speak on DLookup (Note: [blue]you1[/blue] substitute proper names/values in [purple]purple[/purple]):
Code:
[blue]   Dim Cri As String
   
   Cri = "[PrimaryKeyName] = " & Me![PrimaryKeyName]
   
   If Forms![Work Input Form]!Building <> "TBA" Then
      Me.Edit_or_Read_Only = Nz(DLookup("[Count]", "Work Input Form Edit or Read Only Q3", Cri))
      
      If Me.Edit_or_Read_Only = 1 Or Me.NewRecord = True Then
         Me.Read_Only_Title_Bar = "This Record is Editable"
         Me.Form.AllowEdits = True
      Else
         Me.Read_Only_Title_Bar = "This Record is Read Only"
         Me.Form.AllowEdits = False
      End If
   End If[/blue]

BTW ... you really need to do something about your naming convention ... it only makes it harder for you.

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Woops! [surprise]

In the above thread [purple]PrimaryKeyName[/purple] should be in [purple]purple[/purple].

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top