conditional enabling/disabling

G

Guest

I am trying to implement code in my form where if the preivew button is
pressed, if it's a new record, or if you are a certain user (in the code
below the user is Jimmy) that the preview button is enabled. I want to do
this because my preview button allows edits to be performed because sometimes
you catch errors only by seeing the finished report. Once the user moves on
from this form however, I do not want them to be able to hit the preview
button and be able to edit the form again.

Also, as shown below, my code for print preview makes the form advance one
record and then go back one record because it is the only way I could figure
out to get the report preview to reliably view the record currently being
worked on. Otherwise you would have to close the form and then reopen it in
order for it to be correctly viewed in the report.

Here is the code:


Private Sub CmdPreview_Click()
On Error GoTo Err_CmdPreview_Click
Dim preview As Long
DoCmd.Save
preview = Me.Form.CurrentRecord
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acPrevious

Dim stDocName As String

stDocName = "Engineering & Quotation Data Form"
DoCmd.OpenReport stDocName, acViewPreview, , "[EngineeringQuotationID]="
& Me.[EngineeringQuotationID]
Me.AllowEdits = True
Exit_CmdPreview_Click:
Exit Sub

Err_CmdPreview_Click:
MsgBox Err.Description
Resume Exit_CmdPreview_Click

End Sub

Private Sub Form_Current()
Dim user As String
user = CurrentUser()
Dim preview As Long
If Or Me.Form.CurrentRecord = preview Or Me.newrecord = True Or user = Jimmy
Then
Me.AllowEdits = True
Me.CmdPreview.Enabled = True
Else
Me.AllowEdits = False
Me.CmdPreview.Enabled = False
End If
End Sub
 
R

ruralguy via AccessMonster.com

The answer to one of your issues is to have:
If Me.Dirty then Me.Dirty = False
at the top of your code. This will save the current record if needed and
eliminate the need to switch records and back again.
I am trying to implement code in my form where if the preivew button is
pressed, if it's a new record, or if you are a certain user (in the code
below the user is Jimmy) that the preview button is enabled. I want to do
this because my preview button allows edits to be performed because sometimes
you catch errors only by seeing the finished report. Once the user moves on
from this form however, I do not want them to be able to hit the preview
button and be able to edit the form again.

Also, as shown below, my code for print preview makes the form advance one
record and then go back one record because it is the only way I could figure
out to get the report preview to reliably view the record currently being
worked on. Otherwise you would have to close the form and then reopen it in
order for it to be correctly viewed in the report.

Here is the code:

Private Sub CmdPreview_Click()
On Error GoTo Err_CmdPreview_Click
Dim preview As Long
DoCmd.Save
preview = Me.Form.CurrentRecord
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acPrevious

Dim stDocName As String

stDocName = "Engineering & Quotation Data Form"
DoCmd.OpenReport stDocName, acViewPreview, , "[EngineeringQuotationID]="
& Me.[EngineeringQuotationID]
Me.AllowEdits = True
Exit_CmdPreview_Click:
Exit Sub

Err_CmdPreview_Click:
MsgBox Err.Description
Resume Exit_CmdPreview_Click

End Sub

Private Sub Form_Current()
Dim user As String
user = CurrentUser()
Dim preview As Long
If Or Me.Form.CurrentRecord = preview Or Me.newrecord = True Or user = Jimmy
Then
Me.AllowEdits = True
Me.CmdPreview.Enabled = True
Else
Me.AllowEdits = False
Me.CmdPreview.Enabled = False
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top