What's wrong with the VBA???

J

John

Hi Brother,


In the form 'PLCX',there is a combobox "combo71" where I can select
different values(eg: A,B,C)

and there is a Command_Click in the form 'PLCX', which stands for a VBA as
follows:


Dim QY As String

QY = Me.Combo71

Select Case QY

Case QY = "A"

DoCmd.OpenQuery "DLRQ", acNormal, acEdit

Case QY = "B"
....
End Select




When I key "A" in the combo71 and run this VBA,I can open the Query
"DLRQ",however,it does just display 0 records .Actually,it should list where
the field [QY] in the query "DLRQ" is equal to the "combo71" in the form
"PLCX" .

So,what's wrong with the VBA?

If I want to open this query and only show me the list where the [QY] in the
table is equal to the "combo71" in the form "PLCX" .

How should I write this VBA?

Thanks
 
C

CrazyAccessProgrammer

Try Modifying Your Code As Follows:

Select Case Me.Combo71.Value

Case "A"

DoCmd.OpenQuery "DLRQ", acNormal, acEdit

Case "B"

End Select
 
G

gllincoln

Hello John,

I probably would not use the select case statement for this purpose - I
would probably use the value of the combo box to filter the query directly.
(if I understand what you wish to accomplish here).

For example (warning - air code)

(In your command_click event)

DoCmd.OpenQuery "SELECT * FROM [NameOfTable] WHERE [NameOfField]='" &
Me.combo71 & "';"


I am not sure how a select case approach could help unless you were going to
run distinctly different queries based on the value of the selection.
For Example

(Again, in your command_click event)

Dim QY as String
QY=Me.combo71

Select Case QY
Case "A"
DoCmd.OpenQuery "NameOfQueryOne"
Case "B"
DoCmd.OpenQuery "NameOfQueryTwo"
Case Else
MsgBox "No such query!", vbOkOnly, "### INPUT ERROR ###"
End Select
 

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