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!
 
C

Chris O'C via AccessMonster.com

Look in your references. Are any of them listed as missing? Fix them. If
not add a new reference, close the reference window and try to compile again.
Open the references window again and remove the extra reference you just
added. Try to compile again. Go back to the references window. Do you see
any missing references now? Fix them.

Chris
Microsoft MVP
 
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?
 
C

Chris O'C via AccessMonster.com

Did you use the method I suggested to find out if there were missing
references or did you look only once in the references window for "missing"
on a checked reference?

Chris
Microsoft MVP

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.
[quoted text clipped - 9 lines]
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
 
C

Chris O'C via AccessMonster.com

Even if you didn't need that line of code in the form's proc, it should've
compiled.

Chris
Microsoft MVP
 
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.
 
C

Chris O'C via AccessMonster.com

I think I'd try to decompile. Make a copy of the db file and then make a
shortcut with the target in this format:

"path to msaccess.exe" "path to copy of db.mdb" /decompile

In the db copy change the startup form to (none) and rename the autoexec
macro if you have one so no startup procedures run when you first open the db.
Now close the copy of the db. Use the shortcut to open the copy of the db
and decompile it. When it's fully open go to the code editor and try to
compile the code again.

Chris
Microsoft MVP

Even if you didn't need that line of code in the form's proc, it should've
compiled.

Chris
Microsoft MVP
Yes, I tried exactly as you said. I am using 2003, it is a bound form.
[quoted text clipped - 3 lines]
Anyhow, it compiled now, sorry for the alarm but it just (and still does)
have me puzzled a little.
 
L

Linq Adams via AccessMonster.com

In point of fact, Me.Refresh ***does not*** save a record! Refresh is used in
a multi-user environment to allow User A to see changes that User B and User
C have made to existing records! IT does not show new records that User B
and User C have added, nor does it reflect records that they have deleted!

Me.Requery

will save a record, as will

If Me.Dirty Then Me.Dirty = False

that Dirk posted. So will

DoCmd.RunCommand acCmdSaveRecord

I'm thinking maybe using Me.Refresh before the entered data has been saved
may have been responsible for your error.
 
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).
 
C

Chris O'C via AccessMonster.com

"In point of fact, Me.Refresh ***does not*** save a record!"

Yes, it does.

"I'm thinking maybe using Me.Refresh before the entered data has been saved
may have been responsible for your error."

She's getting a compiler error, not a data error. "Method or Data member not
found" is *always* a compiler error and has nothing to do with saving data.

Chris
Microsoft MVP
 

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