update on record

R

rml

I'm using the following with a click command and it works fine. How can I
make it work when I scroll through the records on my form? current, dirty,
etc...

What would be the proper way?

Thanks.


Dim sPartNo As String
Dim sPDFName As String
Const conDrawingFolder As String = "\\server\drawings\"
sPartNo = Me![New2] & vbNullString
If Len(sPartNo) = 0 Then
Image379.Visible = False
Else
sPDFName = conDrawingFolder & sPartNo & ".pdf"
If Len(Dir(sPDFName)) = 0 Then
Image379.Visible = False
Else
Image379.Visible = True
End If
End Sub
 
D

Dirk Goldgar

rml said:
I'm using the following with a click command and it works fine. How can I
make it work when I scroll through the records on my form? current,
dirty,
etc...

What would be the proper way?

Thanks.


Dim sPartNo As String
Dim sPDFName As String
Const conDrawingFolder As String = "\\server\drawings\"
sPartNo = Me![New2] & vbNullString
If Len(sPartNo) = 0 Then
Image379.Visible = False
Else
sPDFName = conDrawingFolder & sPartNo & ".pdf"
If Len(Dir(sPDFName)) = 0 Then
Image379.Visible = False
Else
Image379.Visible = True
End If
End Sub


If I understand you properly, you would just put that code (minus the End
Sub line you quoted) in the Current event of your form:

Private Sub Form_Current()

' ... your code here ...

End Sub

Note, though, that this method can't be used on a continuous form to
show/hide the Image379 control differently for each of the multiple records
displayed. That's because, even on a continuous form, only one record is
current at a time.
 
R

rml

I think I know what is going on. On my form, I have some code that displays
a graphic on current. So, in the on current I have =SetImagePath() so I
think that why the other code is not firing. How can I make them both
co-exist? With the =SetImagePath() I can't go to the code builder? It goes
straight into expression builder. Does all that make sense?

Thanks.

Dirk Goldgar said:
rml said:
I'm using the following with a click command and it works fine. How can I
make it work when I scroll through the records on my form? current,
dirty,
etc...

What would be the proper way?

Thanks.


Dim sPartNo As String
Dim sPDFName As String
Const conDrawingFolder As String = "\\server\drawings\"
sPartNo = Me![New2] & vbNullString
If Len(sPartNo) = 0 Then
Image379.Visible = False
Else
sPDFName = conDrawingFolder & sPartNo & ".pdf"
If Len(Dir(sPDFName)) = 0 Then
Image379.Visible = False
Else
Image379.Visible = True
End If
End Sub


If I understand you properly, you would just put that code (minus the End
Sub line you quoted) in the Current event of your form:

Private Sub Form_Current()

' ... your code here ...

End Sub

Note, though, that this method can't be used on a continuous form to
show/hide the Image379 control differently for each of the multiple records
displayed. That's because, even on a continuous form, only one record is
current at a time.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

rml said:
I think I know what is going on. On my form, I have some code that
displays
a graphic on current. So, in the on current I have =SetImagePath() so I
think that why the other code is not firing. How can I make them both
co-exist? With the =SetImagePath() I can't go to the code builder? It
goes
straight into expression builder. Does all that make sense?


Yep. In order for your Current event procedure to be called, the form's
OnCurrent property must be set to "[Event Procedure]".

If you want to both execute your procedure code and call the SetImagePath()
function, you can call SetImagePath() from your event procedure. Change the
OnCurrent property to "[Event Procedure]" (without the quotes), and build an
event procedure along these lines:

'----- start of example code -----
Private Sub Form_Current()

Dim sPartNo As String
Dim sPDFName As String
Const conDrawingFolder As String = "\\server\drawings\"


On Error GoTo Err_Handler

SetImagePath

' Display or hide Image control, depending on whether
' the PDF is found.

sPartNo = Me![New2] & vbNullString

If Len(sPartNo) = 0 Then
Image379.Visible = False
Else
sPDFName = conDrawingFolder & sPartNo & ".pdf"
Image379.Visible = (Len(Dir(sPDFName)) > 0)
End If

Exit_Point:
Exit Sub

Err_Handler:
' For now, if there's an error -- maybe bad path to server --
' just hide the image control. More comprehensive error
' checking and response should probably be added.
Image379.Visible = False
Resume Exit_Point

End Sub
'----- end of example code -----
 
R

rml

That worked perfect! Thanks.

Dirk Goldgar said:
rml said:
I think I know what is going on. On my form, I have some code that
displays
a graphic on current. So, in the on current I have =SetImagePath() so I
think that why the other code is not firing. How can I make them both
co-exist? With the =SetImagePath() I can't go to the code builder? It
goes
straight into expression builder. Does all that make sense?


Yep. In order for your Current event procedure to be called, the form's
OnCurrent property must be set to "[Event Procedure]".

If you want to both execute your procedure code and call the SetImagePath()
function, you can call SetImagePath() from your event procedure. Change the
OnCurrent property to "[Event Procedure]" (without the quotes), and build an
event procedure along these lines:

'----- start of example code -----
Private Sub Form_Current()

Dim sPartNo As String
Dim sPDFName As String
Const conDrawingFolder As String = "\\server\drawings\"


On Error GoTo Err_Handler

SetImagePath

' Display or hide Image control, depending on whether
' the PDF is found.

sPartNo = Me![New2] & vbNullString

If Len(sPartNo) = 0 Then
Image379.Visible = False
Else
sPDFName = conDrawingFolder & sPartNo & ".pdf"
Image379.Visible = (Len(Dir(sPDFName)) > 0)
End If

Exit_Point:
Exit Sub

Err_Handler:
' For now, if there's an error -- maybe bad path to server --
' just hide the image control. More comprehensive error
' checking and response should probably be added.
Image379.Visible = False
Resume Exit_Point

End Sub
'----- end of example code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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

Top