By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,486 Members | 2,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,486 IT Pros & Developers. It's quick & easy.

Problem with search form

P: n/a
Hi All,
I am creating a music database for a friend and have run into a problem.
Within the ALBUM table, I wanted to store the ARTIST_ID rather than the
ARTIST_NAME. To do this, I intended to have have a command button on the
album form which would open a search form (based on the artist table). This
works as I wanted and allows me to get to one record. I then planned to have
a button on the search form which when clicked, would updated the album form
with the selected artist ID.

I could hard code this but I want to use this search form for other forms
also so I need to know which form to set the value on. I was hoping to use
the openargs value of the search form as I could set this from the form that
opened the search form but I can't figure out how to use this to set the
selected value on whatever form opened it.

I hope this is clear??

Can anyone help?

TIA,

Mark
Dec 28 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Baz
When you open the search form using OpenForm, use the following argument:

WindowMode:=acDialog

This causes the code to suspend execution at the OpenForm statement, waiting
for the opened form (the search form) to be closed.

On your search form, you would typically have two buttons, a Cancel button
and an OK button. The Cancel button closes the search form. The OK button
(and this is crucial!) renders the search form invisible by setting it's
Visible property to False. *Both of these actions will cause the code in
the album form to begin running again*.

Now back in the album form, you test the search form to see if it is still
open. If it is open, you grab the artist_id from it, and then close it. If
it's not open, you know that the user clicked the Cancel button and you
don't have an artist_id.

Example:

DoCmd.OpenForm "frmSearch", WindowMode:=acDialog
If adhIsFormOpen("frmSearch") Then
Me!artist_id = Forms!frmSearch!txtArtistId
DoCmd.Close acForm, "frmSearch"
End If

And here's the function adhIsFormOpen (courtesy of the Access Developers'
Handbook):

Public Function adhIsFormOpen( _
strName As String) As Boolean
' From Access 2000 Developer's Handbook, Volume I
' by Getz, Litwin, and Gilbert (Sybex)
' Copyright 1999. All rights reserved.

On Error Resume Next
Dim fIsOpen As Boolean
fIsOpen = _
CurrentProject.AllForms(strName).IsLoaded
adhIsFormOpen = (Err.Number = 0) And fIsOpen
Err.Clear
End Function

"Mark" <mr*******@btinternet.comwrote in message
news:cO******************************@bt.com...
Hi All,
I am creating a music database for a friend and have run into a
problem. Within the ALBUM table, I wanted to store the ARTIST_ID rather
than the ARTIST_NAME. To do this, I intended to have have a command button
on the album form which would open a search form (based on the artist
table). This works as I wanted and allows me to get to one record. I then
planned to have a button on the search form which when clicked, would
updated the album form with the selected artist ID.

I could hard code this but I want to use this search form for other forms
also so I need to know which form to set the value on. I was hoping to use
the openargs value of the search form as I could set this from the form
that opened the search form but I can't figure out how to use this to set
the selected value on whatever form opened it.

I hope this is clear??

Can anyone help?

TIA,

Mark

Dec 29 '07 #2

P: n/a
Many thanks for the help Baz, worked a treat!!!

Regards,

Mark

"Baz" <ba*@nospam.nowherewrote in message
news:47***********************@news.zen.co.uk...
When you open the search form using OpenForm, use the following argument:

WindowMode:=acDialog

This causes the code to suspend execution at the OpenForm statement,
waiting for the opened form (the search form) to be closed.

On your search form, you would typically have two buttons, a Cancel button
and an OK button. The Cancel button closes the search form. The OK
button (and this is crucial!) renders the search form invisible by setting
it's Visible property to False. *Both of these actions will cause the
code in the album form to begin running again*.

Now back in the album form, you test the search form to see if it is still
open. If it is open, you grab the artist_id from it, and then close it.
If it's not open, you know that the user clicked the Cancel button and you
don't have an artist_id.

Example:

DoCmd.OpenForm "frmSearch", WindowMode:=acDialog
If adhIsFormOpen("frmSearch") Then
Me!artist_id = Forms!frmSearch!txtArtistId
DoCmd.Close acForm, "frmSearch"
End If

And here's the function adhIsFormOpen (courtesy of the Access Developers'
Handbook):

Public Function adhIsFormOpen( _
strName As String) As Boolean
' From Access 2000 Developer's Handbook, Volume I
' by Getz, Litwin, and Gilbert (Sybex)
' Copyright 1999. All rights reserved.

On Error Resume Next
Dim fIsOpen As Boolean
fIsOpen = _
CurrentProject.AllForms(strName).IsLoaded
adhIsFormOpen = (Err.Number = 0) And fIsOpen
Err.Clear
End Function

"Mark" <mr*******@btinternet.comwrote in message
news:cO******************************@bt.com...
>Hi All,
I am creating a music database for a friend and have run into a
problem. Within the ALBUM table, I wanted to store the ARTIST_ID rather
than the ARTIST_NAME. To do this, I intended to have have a command
button on the album form which would open a search form (based on the
artist table). This works as I wanted and allows me to get to one record.
I then planned to have a button on the search form which when clicked,
would updated the album form with the selected artist ID.

I could hard code this but I want to use this search form for other forms
also so I need to know which form to set the value on. I was hoping to
use the openargs value of the search form as I could set this from the
form that opened the search form but I can't figure out how to use this
to set the selected value on whatever form opened it.

I hope this is clear??

Can anyone help?

TIA,

Mark


Jan 5 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.