Why won't this work

F

Flightdisc

Hello,

I'm getting this error from the code below. Can someone explain why!

run-time error '2495':
The action or method requires a Table Name argument.


I have a combo box named cboTables with the following as Value List:

1;Cookies;2;Candy;3;Pie;4;Cake

Then I have this sub with code:

Private Sub cboTables_AfterUpdate()
Dim strRpt As String

Select Case Me.cboTables.Column(1)
Case 1: strRpt = "Cookies"
Case 2: strRpt = "Candy"
Case 3: strRpt = "Pie"
Case 2: strRpt = "Cake"
End Select

DoCmd.OpenTable strRpt, acViewNormal
End Sub
 
J

John W. Vinson

Hello,

I'm getting this error from the code below. Can someone explain why!

run-time error '2495':
The action or method requires a Table Name argument.


I have a combo box named cboTables with the following as Value List:

1;Cookies;2;Candy;3;Pie;4;Cake

Then I have this sub with code:

Private Sub cboTables_AfterUpdate()
Dim strRpt As String

Select Case Me.cboTables.Column(1)
Case 1: strRpt = "Cookies"
Case 2: strRpt = "Candy"
Case 3: strRpt = "Pie"
Case 2: strRpt = "Cake"
End Select

DoCmd.OpenTable strRpt, acViewNormal
End Sub

Well, ordinarily you would not want to open a Table datasheet. Tables are for
data storage, not for presentation!

The root of the problem is that the Column() property is zero based - so it's
comparing the value from the table to the number 1, but what's there is the
text string "Cookies".

If (and I really have to question the logic of the design!!!) you want to do
this, just cut out a step and use

DoCmd.OpenTable Me.cboTables.Column(1)

Column 1 - the *second* column - will already contain the text string Cookies,
and can be passed directly to OpenTable.
 
F

Flightdisc

John,

Awesome dude. With your one line of code I was able to get rid of
everything else in that sub. Dude, if you code my whole database I'll give
you my baseball card collection. Only has one card so far :) YOU ROCK John
W.

Thanks a gazillion!

FD
 
J

John W. Vinson

John,

Awesome dude. With your one line of code I was able to get rid of
everything else in that sub. Dude, if you code my whole database I'll give
you my baseball card collection. Only has one card so far :) YOU ROCK John
W.

If it's a good condition 1920 Babe Ruth in the Yankees ... you're on! <g>

Glad I could help. I would suggest rethinking your design though, if it
involves multiple tables of the same structure - that's as wrong as putting
collectible baseball cards in your bicycle spokes.
 

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