Help run time error

K

Katie

I have the following code attached to a form button and
get run-time error Object Required. What is the problem?
Is the record I get in executing the query not available
in this macro? How do I get around this? Thanks.

Private Sub Command14_Click()

DoCmd.OpenQuery "QueryAv"

If AVAILABILITY.[Booking ID] = 1 Then
'Hide availability form
Forms![SINGLE BOOKING AVAILABILITY].Visible = False
'Open the detail form
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

Exit_Command14_Click:
Exit Sub

End Sub
 
M

Marshall Barton

Katie said:
I have the following code attached to a form button and
get run-time error Object Required. What is the problem?
Is the record I get in executing the query not available
in this macro? How do I get around this? Thanks.

Private Sub Command14_Click()

DoCmd.OpenQuery "QueryAv"

If AVAILABILITY.[Booking ID] = 1 Then
'Hide availability form
Forms![SINGLE BOOKING AVAILABILITY].Visible = False
'Open the detail form
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

Exit_Command14_Click:
Exit Sub

End Sub


I think you want to open a recordset on the query instead of
displaying the query on the screen.

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("QueryAv")

If rs![Booking ID] = 1 Then
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

rs.Close : Set rs = Nothing
Set db = Nothing
 
K

Kate

Tried that and get the message too few parameters expected
3. The following statement gets highlighted:

Set rs = db.OpenRecordset("QueryAv")

Any idea? Thanks

-----Original Message-----
Katie said:
I have the following code attached to a form button and
get run-time error Object Required. What is the problem?
Is the record I get in executing the query not available
in this macro? How do I get around this? Thanks.

Private Sub Command14_Click()

DoCmd.OpenQuery "QueryAv"

If AVAILABILITY.[Booking ID] = 1 Then
'Hide availability form
Forms![SINGLE BOOKING AVAILABILITY].Visible = False
'Open the detail form
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

Exit_Command14_Click:
Exit Sub

End Sub


I think you want to open a recordset on the query instead of
displaying the query on the screen.

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("QueryAv")

If rs![Booking ID] = 1 Then
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

rs.Close : Set rs = Nothing
Set db = Nothing
 
M

Marshall Barton

The query you're trying to get the result from has a
parameter that needs to be resolved. Unlike the Access
environment (database window or form/report recordsource),
the VBA environment does not take care of it for you. If
you need help with that, post back with a Copy/Paste of the
query's SQL and I'll see what I can do.



Tried that and get the message too few parameters expected
3. The following statement gets highlighted:

Set rs = db.OpenRecordset("QueryAv")

Any idea? Thanks

-----Original Message-----
Katie said:
I have the following code attached to a form button and
get run-time error Object Required. What is the problem?
Is the record I get in executing the query not available
in this macro? How do I get around this? Thanks.

Private Sub Command14_Click()

DoCmd.OpenQuery "QueryAv"

If AVAILABILITY.[Booking ID] = 1 Then
'Hide availability form
Forms![SINGLE BOOKING AVAILABILITY].Visible = False
'Open the detail form
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

Exit_Command14_Click:
Exit Sub

End Sub


I think you want to open a recordset on the query instead of
displaying the query on the screen.

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("QueryAv")

If rs![Booking ID] = 1 Then
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

rs.Close : Set rs = Nothing
Set db = Nothing
 
T

tina

hi Marshall.
Kate did post the SQL, in a separate thread 3:59 pm this date, subject line:
I'm struggling with my limited knowledge of code.
i posted an answer (and then a fix to my own answer), but maybe you'll come
up with something better on looking at it?
tina :)


Marshall Barton said:
The query you're trying to get the result from has a
parameter that needs to be resolved. Unlike the Access
environment (database window or form/report recordsource),
the VBA environment does not take care of it for you. If
you need help with that, post back with a Copy/Paste of the
query's SQL and I'll see what I can do.



Tried that and get the message too few parameters expected
3. The following statement gets highlighted:

Set rs = db.OpenRecordset("QueryAv")

Any idea? Thanks

-----Original Message-----
Katie wrote:

I have the following code attached to a form button and
get run-time error Object Required. What is the problem?
Is the record I get in executing the query not available
in this macro? How do I get around this? Thanks.

Private Sub Command14_Click()

DoCmd.OpenQuery "QueryAv"

If AVAILABILITY.[Booking ID] = 1 Then
'Hide availability form
Forms![SINGLE BOOKING AVAILABILITY].Visible = False
'Open the detail form
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

Exit_Command14_Click:
Exit Sub

End Sub


I think you want to open a recordset on the query instead of
displaying the query on the screen.

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("QueryAv")

If rs![Booking ID] = 1 Then
DoCmd.OpenForm "SINGLE BOOKING DETAIL"
End If

rs.Close : Set rs = Nothing
Set db = Nothing
 
M

Marshall Barton

tina said:
hi Marshall.
Kate did post the SQL, in a separate thread 3:59 pm this date, subject line:
I'm struggling with my limited knowledge of code.
i posted an answer (and then a fix to my own answer), but maybe you'll come
up with something better on looking at it?
tina :)


Mutiple threads on the same question arrggghhh.

I did track down the other thread and I think you've nailed
it.
 

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