Queries Dialog Box

G

Guest

I am working on a class assignment. We had to create a queries dialog box.
Then create a load event. It is to select the first query in the list. This
is the code the book says to use:
Private Sub Form_Load()
'Move the focus to the list box and then to the first query in the list
box.
1stQueryList.SetFocus
SendKeys "(Down)"
End Sub
I used a 1 in the example instead of an L because thats what it looks like
in the book. However, this will not work I keep geting a Run Time error 424.

The next problem is we made a command button to open the selected query from
the list. It is supposed to open the query by either double clicking on the
query or using the button. The code for the button is:
Private Function DisplayQuery()
' Open the selected query in Datasheet view.
DoCmd.OpenQuery 1stQueryList, acViewNormal
End Function

I get an error message that says Access doesnt not recognize it.Then for the
On Dbl Click for the Query Box we are to put in =DisplayQuery(). This will
not work either.
 
J

John Spencer

I suspect that that 1stQueryList should be LstQueryList. That is not a one,
but an L. Since one and lower-case L appear to be the same.

Next using SendKeys is bad advice. I'm not sure what book you are using,
but based on this one example I would be very likely to find another text.

You should be able to use
LstQueryList = LstQueryList.ItemData(0) 'assuming the list is not showing
column titles.
or
LstQueryList = LstQueryList.ItemData(1) ' if the list is show column titles

or automatically
LstQueryList = LstQueryList.ItemData(1 + LstQueryList.ColumnHeads)
 
J

John Spencer

Sorry, I have not been able to reproduce this problem in my test database.

Try clicking on the listbox, going to the properties Other tab and copying
the name.
Then paste the copied name into your code in the relevant spots.

Also, try testing it by using some simple code
LstQueryList = LstQueryList

What is error 424? For some reason, I am not raising it as an error.
 
D

Douglas J Steele

John: Error 424 is "Object required"

What are you expecting LstQueryList = LstQueryList to do?


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


John Spencer said:
Sorry, I have not been able to reproduce this problem in my test database.

Try clicking on the listbox, going to the properties Other tab and copying
the name.
Then paste the copied name into your code in the relevant spots.

Also, try testing it by using some simple code
LstQueryList = LstQueryList

What is error 424? For some reason, I am not raising it as an error.
list.
 
J

John Spencer

If the OP got an error on that statement, then I would have expected that
the object did not exist under the name he/she was using.
 
Joined
Nov 14, 2008
Messages
1
Reaction score
0
I had the same problem, but I finally figured out a solution that works (although it isn't exactly coded according to the book).

First of all, 1stQueryList does indeed start with a #1, not a lowercase L. I am sure because that is the name of the Unbound list box on the rptQueriesDialogBox, and that is what we are trying to connect to in this exercise.

The key to the code is to make the VB Editor recognize that 1 is part of 1stQueriesList. This can be achieved by putting the entire name inside [] brackets. So in the case of the first example:

[1stQueriesList].SetFocus

The only catch is that every time the 1stQueriesList appears after that, you have to put it in brackets also. Otherwise the code will not function correctly.

Hope this helps!
 

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