Error 438, Why?

D

David Wetmore

I am trying to transfer a value from one form to another when I activate the destination form and then close the source
form (frmRecordViewer).

When I enable error checking, I get runtime error 438 on the KeyVal assignment line.
When I disable error checking the routine works fine; the value gets transferred and the source form
gets closed.

Private Sub Form_Activate() 'This is for the destination form
Dim KeyVal As Long 'Header Key for Selected Record
On Error Resume Next 'Otherwise error 438, but why?
KeyVal = CLng(Forms.frmRecordViewer.cboEntryName.Column(0))
If CurrentProject.AllForms("frmRecordViewer").IsLoaded Then
DoCmd.Close acForm, "frmRecordViewer"
End If
End Sub 'Form_Activate

What is going on here and what do I do about it?

Thanks

Dave Wetmore
 
D

Douglas J. Steele

See whether it works any better using bangs instead of dots:

CLng(Forms!frmRecordViewer!cboEntryName.Column(0))
 
D

David Wetmore

The bangs did it and the CLng() works fine. Only now, the IF fails. I tried a bang for the first dot, and that gave me
error 438 again.

I'm an old C/C++ programmer, and I find VBA somewhat frustrating (but never boring).

Thanks,
Dave
 
G

Graham Mandeno

Hi Dave

I can't see anything wrong with the If statement, unless you are using a
version of Access before 2000, in which case the CurrentProject object does
not exist and you will need to use a different method:

If SysCmd(acSysCmdGetObjectState, acForm, "frmRecordViewer") <> 0 Then

However, the If statement is either unnecessary or misplaced, because if the
CLng line works then the form *must* be open and there's no need to check.
It would, however, make sense to check that the form is loaded *before*
referencing it in the CLng line.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand
 
D

Douglas J. Steele

There's really no reason for that If statement anyhow. You know the form
must be loaded, or else the line where you assign KeyVal will fail.
 

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