473,383 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Select Case error

imrosie
222 100+
I have a listbox called 'paymnt' ; it has 2 values (check & creditcard). Just below paymnt, I have a command button called 'sendpay' . I am trying to use a Select statement in 'sendpay' based on the paymnt control. I think it can be done.. but it's not working. Can anyone see what a newbie can't? thanks so much. Here's the code:
[code]Private Sub sendpay_Click()
Select Case Me.paymnt.Value
Case "Check"
DoCmd.OpenForm "paymntcrdtcrd"
Case "Credit Card"
DoCmd.OpenForm "paymentchk"
Case Else
End Select
End Sub


I've tried the first line without Value, still didn't work. I've tried using an exclamation between Me and paymnt on first line.

I get a 2447 run-time error "invalid use of the . (dot) or ! operator or invalid parenthesis"

Where am I going wrong?
I've tried to simplify it with this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub sendpay_Click()
  2. If Me![paymnt].Value = 1 Then
  3. DoCmd.OpenForm "paymntcrdtcrd"
  4. Else
  5.  DoCmd.OpenForm "paymntchk"
  6. End If
  7.  
I've searched all over, can't seem to nail this one.

Any ideas??? thanks in advance.
imrosie
Aug 8 '07 #1
12 5183
JKing
1,206 Expert 1GB
List boxes can be tricky. There's a few things you can do but here's one that will flow with what you already have.

Expand|Select|Wrap|Line Numbers
  1. Private Sub sendpay_Click()
  2. Select Case Me.paymnt.ItemData(Me.paymnt.ItemsSelected(0))
  3.   Case "Check"
  4.     DoCmd.OpenForm "paymntcrdtcrd"
  5.   Case "Credit Card"
  6.     DoCmd.OpenForm "paymentchk"
  7.   Case Else
  8. End Select
  9. End Sub
  10.  
Me.paymnt.ItemsSelected(0) returns the row that is selected.
Me.paymnt.ItemData returns the value for the specified row.

Give that a try and let me know how it worked out.
Aug 8 '07 #2
imrosie
222 100+
List boxes can be tricky. There's a few things you can do but here's one that will flow with what you already have.

Expand|Select|Wrap|Line Numbers
  1. Private Sub sendpay_Click()
  2. Select Case Me.paymnt.ItemData(Me.paymnt.ItemsSelected(0))
  3.   Case "Check"
  4.     DoCmd.OpenForm "paymntcrdtcrd"
  5.   Case "Credit Card"
  6.     DoCmd.OpenForm "paymentchk"
  7.   Case Else
  8. End Select
  9. End Sub
  10.  
Me.paymnt.ItemsSelected(0) returns the row that is selected.
Me.paymnt.ItemData returns the value for the specified row.

Give that a try and let me know how it worked out.
Thanks so much for this...I tried it and it failed though with the following error message:
run-time error 2480 "You referred to a property by a numeric argument that isn't one of the property numbers in the collection......

that's over my head (I still speak Newbie)...any ideas?
thanks
Rosie
Aug 8 '07 #3
JKing
1,206 Expert 1GB
ItemsSelected Property is a collection that holds all the row values for any selected items in the listbox. If no item is selected you'll get that error. I think I may have over complicated this.

Let's take a look at your listbox properties.
If you're using a value list They should look like this:
Expand|Select|Wrap|Line Numbers
  1. Row Source Type.... Value List
  2. Row Source............ "Check";"Credit Card"
  3. Column Count......... 1
  4. Bound Column........ 1
  5.  
You should be able to use your original code with this setting.
Expand|Select|Wrap|Line Numbers
  1. Private Sub sendpay_Click()
  2. Select Case Me.paymnt.Value
  3.   Case "Check"
  4.     DoCmd.OpenForm "paymntcrdtcrd"
  5.   Case "Credit Card"
  6.     DoCmd.OpenForm "paymentchk"
  7.   Case Else
  8.     Msgbox "Please choose a payment method"
  9. End Select
  10. End Sub
  11.  
On the other hand if you are using an alternate record source then it will change things slightly. The value property of a list box returns the value in the bound column for the item selected in the list. So, if you're using a query and hiding the key column the listbox is bound to you will need your Case statements to correspond with the values of the key column.
Aug 8 '07 #4
missinglinq
3,532 Expert 2GB
Just slightly off subject , but if the user selects "Check" do you really want to open a form named "paymntcrdtcrd" and vice versa, open a form named "paymentchk" if "Credir Card" is chosen?

Linq ;0)>
Aug 8 '07 #5
missinglinq
3,532 Expert 2GB
While Access' error messages are often esoteric and sometimes even slam off the wall, you should at least glance at them and see if they apply.

"invalid use of the . (dot) or ! operator or invalid parenthesis"

Now where in your code did you use the . (dot) or ! operator?

Right, in Select Case Me.paymnt.value. This code works just fine, just using the name of the control:

Expand|Select|Wrap|Line Numbers
  1. Private Sub sendpay_Click()
  2.   Select Case paymnt
  3.    Case "Check"
  4.     DoCmd.OpenForm "paymntcrdtcrd"
  5.   Case "Credit Card"
  6.    DoCmd.OpenForm "paymentchk"
  7. Case Else
  8. End Select
  9. End Sub
Notice, I left your code as you posted it, but as I said in my previous post, it looks like you have your forms reversed!

Good Luck!

Linq ;0)>
Aug 8 '07 #6
JKing
1,206 Expert 1GB
Should also work using .value as access has default properties for all controls and the listbox's is the .value property. Still if it's not functioning properly I believe it would have to do with the listbox's bound column.

P.S. Good spot on the name mix up Linq!
Aug 8 '07 #7
missinglinq
3,532 Expert 2GB
Actually, I went back and ran her original code and it works for me. I have to assume Rosie used the listbox wizard to make the listbox, so everything should be set on the default settings and it's not like it's complicated, you got two choices! Of course, anytime something simple that should work in Access doesn't work , you have to think about $)@*%^&^!@ corruption!

If you still can't get it working, Rosie, you might want try deleting the listbox and re-creating it.

Linq ;0)>
Aug 8 '07 #8
imrosie
222 100+
ItemsSelected Property is a collection that holds all the row values for any selected items in the listbox. If no item is selected you'll get that error. I think I may have over complicated this.

Let's take a look at your listbox properties.
If you're using a value list They should look like this:
Expand|Select|Wrap|Line Numbers
  1. Row Source Type.... Value List
  2. Row Source............ "Check";"Credit Card"
  3. Column Count......... 1
  4. Bound Column........ 1
  5.  
You should be able to use your original code with this setting.
Expand|Select|Wrap|Line Numbers
  1. Private Sub sendpay_Click()
  2. Select Case Me.paymnt.Value
  3.   Case "Check"
  4.     DoCmd.OpenForm "paymntcrdtcrd"
  5.   Case "Credit Card"
  6.     DoCmd.OpenForm "paymentchk"
  7.   Case Else
  8.     Msgbox "Please choose a payment method"
  9. End Select
  10. End Sub
  11.  
On the other hand if you are using an alternate record source then it will change things slightly. The value property of a list box returns the value in the bound column for the item selected in the list. So, if you're using a query and hiding the key column the listbox is bound to you will need your Case statements to correspond with the values of the key column.
No, JKing,

You're exactly right with my listbox properties. I'm scratching my head...
Rosie
Aug 8 '07 #9
imrosie
222 100+
Just slightly off subject , but if the user selects "Check" do you really want to open a form named "paymntcrdtcrd" and vice versa, open a form named "paymentchk" if "Credir Card" is chosen?

Linq ;0)>
Missinglinq,
you're right, I must have criss crossed the "check" with the "credit card" statements, I'll fix that. thanks

Rosie
Aug 8 '07 #10
JKing
1,206 Expert 1GB
I'm quite curious to see what value is being produced by the list box.

Throw a Debug.Print under the click event like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub sendpay_Click()
  2. Debug.Print Me.paymnt.Value
  3. 'rest of code here
  4. End Sub
  5.  
Make sure you have the immediate window open so you can see the results. Ctrl+G will open it from the VBA editor window. Try this twice. Once with check selected and once with Credit card selected and see what results.
Aug 8 '07 #11
imrosie
222 100+
Hello JKing and Missinglinq,

I re-created the listbox...it works beautifully (also made sure the "check" and "creditcard" select statements were correct.
thanks for your help.
Here's the code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub sendpay_Click()
  2. Private Sub sendpay_Click()
  3. Debug.Print Me.paymnt.Value
  4. Select Case Me.paymnt.Value
  5.   Case "Check"
  6.     DoCmd.OpenForm "paymntchk"
  7.   Case "Credit Card"
  8.     DoCmd.OpenForm "paymentcrdtcrd"
  9.   Case Else
  10.     MsgBox "Please choose a payment method"
  11. End Select
  12. End Sub
  13.  
thanks again,,,I don't know what was wrong before.
Rosie
Aug 8 '07 #12
missinglinq
3,532 Expert 2GB
Glad you got it fixed, Rosie!

Linq ;0)>
Aug 9 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
9
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
3
by: blue | last post by:
I'm trying to order a varchar column first numerically, and second alphanumerically using the following SQL: SELECT distinct doc_number FROM doc_line WHERE product_id = 'WD' AND doc_type = 'O'...
10
by: Lakshmi Narayanan.R | last post by:
Hi Experts, Using keyword "To" in select case giving error.The following code is got from www.microsrosoft.com itself. What is the wrong with this?. <% Dim Number1 Number1 = 7 ' Initialize...
8
by: Penny | last post by:
Hi all, My browser throws this Select Case block back at me pointing out a syntax error on the line: 'Case < 251', between the word 'Case' and the '<' symbol. *************************** ...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
3
by: Rob Meade | last post by:
Ok - I *think* this is only different in .net 2.0 - as I've not had any problems in the past, but then maybe I've not tried it... I have a value being read from an xml file where the value maybe...
25
by: CJM | last post by:
I'm getting a syntax error with a Select Case statement: Select Case CSng(rs.fields("Field1")) Case 0 Response.Write "Test1" Case Is < 0 <<< Syntax Error...
2
by: scole954387 | last post by:
Hi, I have a problem. I have written a SQL statement that has a nested select case statement on the 'where' clause to condition the results. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.