Hi Roger,
Try this:
Private Sub PLANNED_GIVING_PROGRAMME_Click()
Dim stDocName As String
Dim stFindRecord As String
On Error GoTo Err_PLANNED_GIVING_PROGRAMME_Click
stDocName = "Planned Giving Programme"
If InputBox("Please Enter Password") = "roger" Then
If Me.Dirty Then Me.Dirty = False 'force save of any pending edits
DoCmd.OpenForm stDocName
Forms(stDocName).RecordSet.FindFirst "[Envelope Number] = " &
Me.[Envelope Number]
Else
MsgBox "Sorry, Incorrect Password"
End If
Exit_PLANNED_GIVING_PROGRAMME_Click:
Exit Sub
Err_PLANNED_GIVING_PROGRAMME_Click:
MsgBox Err.Description
Resume Exit_PLANNED_GIVING_PROGRAMME_Click
End Sub
Note also that I've moved your On Error GoTo statement to the start of the
routine, so that it will be triggered if an error occurs during the routine.
It also occurs to me to wonder why you have two forms with the same
recordsource. Why not simply put controls for all the fields you want on
the first form? If there are a lot of them (possibly a sign of
non-normalised data structure, but not necessarily), you could use a tabbed
interface on your form to group the controls into logical sets; however,
they would still all be on the same form, so the issue of opening another
form and navigating to the same record would be avoided.
Rob
Roger Bell said:
Thanks for that Albert. Would you be able to tell me the exact code in
relation to the Event Procedure as follows:
Private Sub PLANNED_GIVING_PROGRAMME_Click()
stDocName = "Planned Giving Programme"
If InputBox("Please Enter Password") = "roger" Then
DoCmd.OpenForm stDocName, , , "[Envelope Number] = " & Me.[Envelope
Number]
Else
MsgBox "Sorry, Incorrect Password"
End If
On Error GoTo Err_PLANNED_GIVING_PROGRAMME_Click
Exit_PLANNED_GIVING_PROGRAMME_Click:
Exit Sub
Err_PLANNED_GIVING_PROGRAMME_Click:
MsgBox Err.Description
Resume Exit_PLANNED_GIVING_PROGRAMME_Click
End Sub
Albert D. Kallal said:
Thanks for that Rob. Got it to work thanks to your expertise.
However,
when
you move to the other form it filters just the record you are on. The
user
needs to be able to acccess other records whilst in this screen. Is
there
a
way to do this?
Thanks again for your valued support
Yes, you can accomplish you goal. As a side note, the movign to ONE
reocrd
is perffered from a performance point fo view. Designs that limit, or
only
load one reocrd to a form tend to be very high perframance appcations.
however, do accoplish your goal, the soltion then is to remote the
"where"
clause, and simply *move* to the same reocrod.
Here is how the code will look:
' the first thing to remmber is that if you ALLOW editign of data in the
first form, but then open a 2nd form to the SAME reocord, you MUST FORCE
A
DISK WIRITE in the first form (else, you ahve two forms open to the saem
reocrd..and BOTH will want to save their changes!!!).
so, the follwing code will force a disk write in our first form. You can
IGRNORE/remove the folwlign code if you don't allow editign in the first
form
dim strF as string
' write current reocrd to disk before lanching 2nd form
if me.Dirty = true then
me.dirty = false
end if
strF = "YourFormName"
' open 2nd form
DoCmd.OpenForm strF
' move 2nd form to same reocrd
forms(strF).reocrdSet.findFirst "id = " & me!id