Do.Cmd OpenTable

Woodstock

New member
Local time
Today, 17:48
Joined
May 29, 2017
Messages
4
I haven't used access in years and am trying to help my son learn to use it, but encountering some errors on basic VBA code

He has a form with various buttons eg next record etc. He is trying to use a button to open the underlying table. The underlying code is as follows:

Private Sub View_Click()
DoCmd.Close
DoCmd.OpenTable "tblPerformers", , , ""
End Sub

He keeps getting a compile error"wrong number of arguments or invalid property assignment"

any help would be greatly appreciated.
 
The correct syntax is

expression .OpenTable(TableName, View, DataMode)

By my count, you have FOUR arguments including the table name. The trailing "" is the 4th argument. The syntax says you only want three including the table name. That would certainly qualify for "wrong number of arguments."

See: https://msdn.microsoft.com/en-us/library/office/ff194975.aspx
 
thanks Doc_Man for your prompt reply

The code I posted is what was given by the school. I did notice the additional argument and tried deleting it, but then got the following error:
Run type error"13":
Type Mismatch
 
You don't replace arguments, using a comma, if there are no further arguments, so

DoCmd.OpenTable "tblPerformers", , , ""

should simply be

DoCmd.OpenTable "tblPerformers"

The advisability of actually opening a Table, independently of a Form, is another question entirely!

Linq ;0)>
 
Agree with linq about opening a table, but if this is a school assignment, it might be what you have to do.

If this is NOT a school assignment, opening a table is risky business.
 
Agree with linq about opening a table, but if this is a school assignment, it might be what you have to do.

If this is NOT a school assignment, opening a table is risky business.

Thanks...it was a typo in the school assignment...all sorted now...thanks
 

Users who are viewing this thread

Back
Top Bottom