Full Version: microsoft access form records..
UtterAccess Forums > Microsoft® Access > Access Forms
wazdaman
hey,
asically ive got two forms and they are both linked through an unbound text box. one form is the patient information and the other is the medical history.
what i need is that when u click on the patient information it should open the medical history of the same patient which you were on.
I have looked through macros and found out that you can either go to last, first, next, previous or what ever record you need to go to but i cant see an option which keeeps the same record on.
could someone help...
Jack Cowley
Your tables should be linked on the PatientID field in the Patient form. The MedicalHistoryt table should be a subform on the Patient form. Selecting a patient in the main form will show their medical history in the subform.
th,
Jack
SerranoG
When you say they are "linked through an unbound text box," did you mean a textbox on a third form? Is the textbox in a mainform and the two other forms subforms on this main form?
Yes, you can go to any record, but don't do it off a macro. Do it in VBA code. OK, let's make some assumptions. If your texbox is on the third form, and clicking a button opens the other two forms you mentioned, the the button's ON CLICK event would have something like this:
CODE
DoCmd.OpenForm "frmFormA", , , "[strMyText] = '" & Me.txtMyTextBox & "'"
DoCmd.OpenForm "frmFormB", , , "[strMyText] = '" & Me.txtMyTextBox & "'"

Oused fake names for the two forms, the underlying field, and the textbox. Replace them with your own.
wazdaman
thanx mate
rrm will the sub form be shown or will it be invisible until you have clicked the thingy
Jack Cowley
The subform should always be visible, but it will show the related record of the record on the main form when the main form is open. If, for example, the main form opens to the tables first record the data shown in the subform will be the related record for the first record.
th,
Jack
wazdaman
greg serrano,
That does
strMyText
stand for and
Me.txtMyTextBox
stand for
Jack Cowley
To respond to Greg open his post. To the right of his avatar click on Reply and then put your question in the Reply box at the bottom of the form. Now Greg will know that you have posted a question to him.
ack
wazdaman
greg serrano,
dont fully understand ur code.
what does
strMyText
stand for and
Me.txtMyTextBox
stand for
wazdaman
jack
Is there a way in which i could show the information of medical history and then form a click it could dissapear or even get compressed or something.
Jack Cowley
If you do not want to see the MedicalHistory subform you can set its Visible property to No. You can turn this property off and on, using code, if you like. Something like:
e.SubformControlName.Visible = True
For
Me.SubformControlName.Visible = False
hth,
Jack
wazdaman
ok
dont knw how to create a sub form i have seen some examples but they are really different to the one which you create from the toolbox
SerranoG
Hi, wazdaman.
trMyText and Me.txtMyTextBox are fake names I used to represent the field in your table and the textbox in your form you were talking about. Because I didn't know their real names, I used fake names and then mentioned that in my original note so you can replace them with your real names.
In general, when a user in UA doesn't supply names for control objects, forms, reports, etc., people trying to solve the problem use fake names and assume you will know this and substitute your real names for things. They often use fake names like
"Your Report", "Your Form Name Here", strYourTextField, txtMyTextBox, cboMyComboBox, etc.
The "Me." is an Access shortcut for the name of your form or report. So, for example, if your form's name was frmFormA and your textbox's name is txtMyTextBox, then you can refer to the textbox like this: Forms.frmFormA.Form.txtMyTextBox or simply Me.txtMyTextBox.
In this case, Me. is a shortcut for Forms.frmFormA.Form.
Jack Cowley
Create you main form based on your Patient table and save it. Create a new form, Datasheet view, based on MedicalHistory table and save it. Now open your Patient form in Design view and using the Subform tool from the ToolBox menu add your MedicalHistory form to the Patient form. If you have your joins between these two tables set up correctly Access will properly link the subform to the main form and you should be good to go. If this is not enough help I believe that if you search Access help for Subforms that you will find more information there, but this should get you started and should work.
th,
Jack
wazdaman
ok
o if i give you the names of my fields then will u be able to make the code.
im new to this thing and im not really patient so the quicker the better.
Form Name: frmPatientInformation
in this form there is an unbound text box called (strMedicalHistory). when you click on this another form opens which is called (frmMedicalhistory) .
I think these are all the fields names u need or u mite need the table as well.
table name: tblPatientData.
wazdaman
jack,
ve got the patient information form saved and the medical history form saved how do i put the medical history form into a sub form,
wazdaman
ahh i have found out how to do it
Thank YOU
Jack Cowley
Read this earlier reply...
ack
Jack Cowley
You are welcome and I'm glad you figured it out. Now be sure that your related table (MedicalHistory or whatever it is called) is properly related to the PatientInformation table.
ack
wazdaman
ok
Below are the names
so if i give you the names of my fields then will u be able to make the code.
im new to this thing and im not really patient so the quicker the better.
Form Name: frmPatientInformation
in this form there is an unbound text box called (strMedicalHistory). when you click on this another form opens which is called (frmMedicalhistory) .
I think these are all the fields names u need or u mite need the table as well.
table name: tblPatientData.
ScottGem
>
We don't do homework assignments for you. We will help by answering specific questions, but you need to do the work yourself. That's how you learn.
wazdaman
thanks jack i have got the sub fom to work but knw i need to find a suitable place for it and yes ill be able to do that
Thanks for your help and i probably wont be posting on this site from knw on due to people like ScottGem who has insulted me
Jack Cowley
If your main form has limited space you can open a separate MedicalHistory form to show the records that go with the PatientID on your main form. Create a new form and probably in Continuous form mode. Add a command button to the main form and use code like this to open the new MedHist form to the correct record(s):
oCmd.Openform "frmMedHist", , ,"[PatientID] = " & Me.NameOfControlOnMainFormWithPatientID
I'm very sorry to hear that you feel it necessary to look elsewhere for answers to your Access questions. You might want to PM (Private Message) Scott and tell him that you felt insulted by his comment and see if you can work it out. Have you received other posts that you felt were insulting? Is so, I would like to know. If you would like to discuss this further you can PM me and we can talk about it.
Jack
wazdaman
dont worry jack i do not want to discuss this matter any further. an thank you for your concern
I have found a space for the sub form but have come across a problem.
I have used the code you gave me previously:
Me.SubForm1.Visible = True -----i have put this in the unbound text box. (works perfectly)
Me.SubForm1.Visible = False ------i have put this in a command button in the sub form. (but doesn't work)
and when the sub form opens in the main form it displays the correct data.
but when i scroll through my records on the main form the data on the sub form do not change is there a way in which i can make the data also cycle through the records when im clicking on the main form..
thanx
Jack Cowley
Put the command button to set the subforms visible property to No on the main form.
If you added the subform to the main form using the Wizard then the Master/Child links should have been set for you. Check them to make sure you have them set correctly as the subform should change as you move between records on the main form.
Jack
wazdaman
oohh
didnt use the wizard
thanx i will do knw
wazdaman
it says the wizard feature is not installed
will have to do it tomorrow
and errmm if i do it from the wizards way then whe i open the sub form and scroll through on the main form will the sub form dataalso change.
Jack Cowley
The subform data will change as you move through the records in the main form. You do not need the Wizard as you can type in the Master/Child links or click on the button to the right (with 3 dots) and use the dialog that opens to select the links.
ack
wazdaman
Yes thank you the records are knw cycling through but the other problem is still not working.
e.SubForm1.Visible = False ------i have put this in a command button in the sub form. (but doesn't work)
when i put this code in the sub form it doesn't seem to work but if i put it outside in the main form then it does work.
is there a special way in which you can do this in the sub form.
wazdaman
Can you hide a control that has the focus as that is the error which comes up.
wazdaman
this is the new code which i am knw trying to get to work.
e.Form.Visible = False
Jerry Dennison
Use the following in the button's OnClick event:
..
Me.SubFormName.Visible = Not Me.SubFormName.Visible
...
That will toggle the subform. Use "Show/Hide Subform" as the caption of the button.
niesz
>I think the issue is that the button to hide the subform is in the subform itself. You may need to reference the subform name through the Main form.
lso, because the focus is on the button of the subform, you have to move focus off of the subform before hiding it.
Forms.YourMainFormName.SomeControlOnYourMainForm.SetFocus
Forms.YourMainFormName.YourSubFormCONTROLName.Visible = False
wazdaman
Forms.YourMainFormName.SomeControlOnYourMainForm.SetFocus
Forms.YourMainFormName.YourSubFormCONTROLName.Visible = False
omeControlOnYourMainForm (IS THIS THE NAME OF THE COMMAND BUTTON WHICH YOU CLICK TO MAKE THE VISIBLILITY FALSE.)
wazdaman
jerry an error also occurs in this do i put the "show/hide sub form" command button out side the sub form or in it.
niesz
Let me rephrase, for clarification.
How many command buttons do you have?
Is there one on the Main form to Show the subform and another one on the subform to Hide it?
...or...
Is there only one button on the Main form, that when you click it once it Hides the subform and when you click it again it Shows the subform?
wazdaman
well on the main form there is an unbound text bocx which when you click opens the sub form.
On the sub form there is a command button which when you click hides the sub form
niesz
So, then to answer your question, the SomeControlOnYourMainForm could be your unbound textbox name.

EDIT: The important part is that no control on the SUB form can have focus when you hide it. So you have to SET focus some place else (preferably the Main Form).
wazdaman
ok i get it knw
hanx
niesz
Glad to help.
wazdaman
yes thank you that also works
Jerry Dennison
The command button should be on the main form. Not the subform.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.