What's wrong with this code? I keep getting an error

S

Scuda

Hi guys, when attempting to compile in VB, it keeps stopping here:

Private Sub cmdPrintPreview_Click()
Me.Refresh ' this forces a disk write
DoCmd.OpenReport "rptSITReliefSheet", acPreview, , "id = " & Me!id
End Sub

and giving me an error stating Compile Error: Method or Data member not
found. I have been using this command for a while with no problems. I use it
to go to the last report.

Thanks!
 
D

Dirk Goldgar

Scuda said:
Hi guys, when attempting to compile in VB, it keeps stopping here:

Private Sub cmdPrintPreview_Click()
Me.Refresh ' this forces a disk write
DoCmd.OpenReport "rptSITReliefSheet", acPreview, , "id = " & Me!id
End Sub

and giving me an error stating Compile Error: Method or Data member not
found. I have been using this command for a while with no problems. I use
it
to go to the last report.


Are you sure "id" is the name of a control on your form?
 
D

Dirk Goldgar

Scuda said:
Thanks guys, I have no missing references, and I confirmed that is
actually
on the form. When it highlites the error, it highlites the .Refresh don't
know if that helps or not.

That's odd. You're sure this code is on a form? Is the form bound, or is
it unbound? What version of Access are you using?
 
S

Scuda

Yes, I tried exactly as you said. I am using 2003, it is a bound form.

I deleted that code (the Me.Refresh) and my function still worked so maybe
it was just the "extra" code that flagged it?

Anyhow, it compiled now, sorry for the alarm but it just (and still does)
have me puzzled a little.

thanks for the help, much appreciated.

Steph
 
D

Dirk Goldgar

Scuda said:
Yes, I tried exactly as you said. I am using 2003, it is a bound form.

I deleted that code (the Me.Refresh) and my function still worked so maybe
it was just the "extra" code that flagged it?

Anyhow, it compiled now, sorry for the alarm but it just (and still does)
have me puzzled a little.


I wouldn't be happy with this solution, if I were you. First, the expressed
purpose of calling Me.Refresh, according to the comment, is to force the
current record to be saved before running the report. If that's necessary,
you can't afford to leave it out -- you must use this or another method to
save the record, or else the current record's values won't appear on the
report. Personally, I prefer to use this method instead of Refresh:

If Me.Dirty Then Me.Dirty = False

You may want to consider placing that line in the code instead of the
Me.Refresh.

Second, and even more important, is that if Me.Refresh won't compile on an
Access form, something is seriously wrong. Possibly you have a broken
reference, as Chris O'C has been suggesting, or possibly your database's VB
project is corrupt. If that's the case, lots of other things are likely to
go wrong, too. I recommend you address the problem, find out what is
causing it, and fix it.
 
D

Dirk Goldgar

Linq Adams via AccessMonster.com said:
In point of fact, Me.Refresh ***does not*** save a record!

Pardon, but "Me.Refresh" *will* force the record to be saved, before
returning any changes to existing records. If the goal is to force the
current record to be saved, it's a much better choice than "Me.Requery"
(which reruns the form's recordsource query), but not as good a choice as
"Me.Dirty = False" or "RunCommand acCmdSaveRecord" (both of which save the
current record without doing anything else).
 

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