question about the form

vicgirl

Registered User.
Local time
Today, 15:19
Joined
Jul 13, 2004
Messages
33
Hi,
I have a question when I set flag for the form.
I have two forms: one is called Entryform and the other is called SearchForm.
The Entryform shows all the records in the table Maintable; this form is set to an empty record when the form is open.
The SearchForm retrieves the records which only meet certain criteria and it shows the ID of the records. When the ID is clicked,
the EntryForm is open and the data about the record should be showned.
My problem is that when the ID is clicked in the SearchForm, the empty record is showed first instead. I have to click <| button at bottom of the form to see the record which should be display.
To solve this problem, I created a public variable called flag to check if it is in the SearchForm or just Open EntryForm.
In the SearchForm, my code for ID_Click() is
DoCmd.OpenForm "Log Entry Form", , acFormReadOnly, "ID=[forms]![search_form]![ID]"
flag = True
In the EntryForm, the code for Open_Form() is
If flag = True Then
flag = False
Else
DoCmd.GoToRecord , , acNewRec
End If
However, it doesn't work. Anyone knows how to solve this problem? Thanks!
 
Hi

The Open_Form() code will cause the form to open at a new record, why do you need this code when you are opening the form from code with the required ID?

Brian
 
That is one of the requirements. Each record contains many detailed information and it is impossible to show all of the information in the searchForm. Hence, in the searchForm, only ID, Name, etc. main fields are showned.


Brianwarnock said:
Hi

The Open_Form() code will cause the form to open at a new record, why do you need this code when you are opening the form from code with the required ID?

Brian
 
Last edited:
Hi reread your post ok I now understand what you wish to do. Assuming that your post truly represents your code move the flag = statement before the DoCmd OpenForm statement otherwise it won't work first time through. I am assuming that the search form is not opened from the entryform, if it is then the open event will not take place, and thus I don't know what is wrong.

To clarify Move statements as stated, it should now work however you are doing it.

If you are calling the search form from the entry form, as i would, then the openevent is not activated see access vba help.

Brian
 
Thanks, Brian. The Searchform is a seperated form from entryform. I have move the flag = statement before the openForm in the searchform (I assume this is what you mean), however, I still get the same problem. It is an empty record when I click the ID of one of the results.
 
Last edited:
Yes that is what I meant.
The only time I could reproduce your problem was when
1 The search form was separate from the main form
2 I opened only the search form on entering the database
3 The flag statement was after the open main form statement (this was an accident :D )
when I now clicked on the ID I got your situation, bound to as the flag would not be set to true and as the main form was not open the open event would be used.
At all other times everything was ok.

I am at home now and will not be in work till Monday,parttimer :) , and as my wife does not have Access on her home computer I will not be able to look at it again , but I cannot see what you are doing to cause the problem from the info given.
Is the code in the Entry Forms Open_Form() event the only point at which you got to a new record?

Brian
 
vicgirl said:
It is an empty record when I click the ID of one of the results.

Do you just get the empty record or do you get the requested record aswell ie 2 records? If its the latter I am none the wiser, if its the former I am going to suggest something that might be brilliant or crazy :confused:

I could not get my DoCmd.OpenForm "frmMain", , acFormReadOnly, "ID=[forms]![search_form]![ID]" to work coded like this I was prompted for the parameter [forms]![search_form]![ID] and on entering an ID got the record perhaps I would have got ablank record if I had just hit enter.
I had to code
strID = "[ID] = " & Me![ID]
and then use strID as the 4th parameter of the DoCmd OpenForm
( all this is from memory I hope its correct.
Then everything worked ok.

Brian
 
Thanks for your help, Brian. I appreciate it.
The acNewRecord exists in form_open() and open_form_click(). I have the same problem when I deleted the acNewRecord in the open_form_click().
Actually I have got an empty record as well as the record which has the ID. I put the sample database as attachment. It will explain more clearly.
 

Attachments

Last edited:
Hi,
As I said or implied in a previous post I will not have access to ACCESS till Monday, I will look then but hopefully somebody else will have had a look and solved your problem before then.

Brian
 
Hi

Remove the Public declaration of flag from the search_form code into a separate code Module, I called mine basPublic. It should all work fine now.

Brian
 

Users who are viewing this thread

Back
Top Bottom