Full Version: Opening a form based on individual record
UtterAccess Forums > Microsoft® Access > Access Forms
Acess_help
All my records are displayed on a form. Upon clicking on their respective 'View' button, I would like to open that particular record. How can I do that? I have attached a screenshot for better clarity. Thanks in advance for the help!
danishani
U can use a where criteria to open your form based on the current ID you are in:
oCmd.OpenForm "yourFormName", , , "MyID=" & Me.ID
Hope this is working let me know.
Daniel
kapeller
Hi Swee!!!
Have a look at this link. It may be what you are looking for.
Link
Cheers!!!!
Lou
Acess_help
Hi all
aniel's code got it working! Thanks. I thought that wouldnt work because the form wouldnt know which record's value to retrieve and so I did not try it out initially. But well, it works. Thanks again!
danishani
Great, glad u got it working frown.gif
aniel
Acess_help
I have another question. If I wanna show approve and reject buttons for records that have not been vetted yet, how do I do that? This means that records that are not vetted will have those buttons' visible properties set to True and so on.
ill the If condition i specify at the Form_Load event loop through every record or will it stop after the first record?
danishani
For understanding, what do u mean with records are vetted?
omething like this?
If [YourFieldName]="Vetted" Then
[YourButtonName].Visible = False
Else
[YourButtonName].Visible = True
End If
HTH
Daniel
Acess_help
I have this code on the Form_Load event of my form. The form is to let users view all purchase orders and whether they have been approved. If they have not been approved, then the buttons will be set to be visible. There are 2 records on my form now; the first is approved, the second not approved yet.

When I open the form, no buttons are shown at all. My guess is that Access goes into the first loop and then sets the buttons to be invisible as the first record has already been approved. In this way, the second record is neglected. Hope I have made it clearer.

CODE
If DLookup("[Approved]", "tblOrderInfoMain", "[PONumber]='" & Me![Subform].Form![PONum] & "'") = -1 Then
nbsp;        Me![Subform].Form![btnApprove].Visible = False
         Me![Subform].Form![btnReject].Visible = False
              
ElseIf DLookup("[1stRecommender]", "tblOrderInfoMain", "[PONumber]='" & Me![Subform].Form![PONum] & "'") = -1 Then
         If strUserID = "jntan" And Me![Subform].Form![txtTotalPrice] < 2000 Then
                Me![Subform].Form![btnApprove].Visible = True
                Me![Subform].Form![btnReject].Visible = True
         End if
End If

Edited by: Acess_help on Wed Oct 6 5:22:25 EDT 2004.
danishani
Try this:
CODE
  
If DLookup("[1stRecommender]", "tblOrderInfoMain", "[PONumber]='" & Me![Subform].Form![PONum] & "'") = -1 Then
         If strUserID = "jntan" And Me![Subform].Form![txtTotalPrice] < 2000 Then
                Me![Subform].Form![btnApprove].Visible = True
                Me![Subform].Form![btnReject].Visible = True
Else
         Me![Subform].Form![btnApprove].Visible = False
         Me![Subform].Form![btnReject].Visible = False
        End If
End If

HTH
Daniel
Acess_help
Hmmm, it doesnt loop through all the records, Daniel. If the first record is approved, all the records below it will show the buttons irrespective of whether they are approved. How can I loop through each record?
danishani
Yep sorry, I am not aware on how you setup the structure. Is it possible to post an example, so I can try to work it out for you?
aniel
Acess_help
Ok I have uploaded a sample of my db. Hope you understand it now. Thanks so much for the help. laugh.gif
danishani
Okidoki, I understand, I put some code in the On_Current event of your subform, so if the use is in a record where there Aproved is ticked (True) then the buttons are not visible, else the buttons will show up.
See attachment...
HTH
Daniel
Acess_help
Hi Daniel,
think it only works when I focus on the record. And even so, it affects all the buttons as well. Can I have them show the buttons only in those rows that have not been approved?
danishani
Hi,
hats right, because its continues form, so what u can do is make the buttons already invisible by opening the form, so it will only be visible when the record got the focus.
HTH
Daniel
Acess_help
I see. Is there any other way besides the On_Current event? I'm afraid the users might find it confusing to see the buttons on every row, regardless of whether they have been approved.
danishani
Hi there,
So, at least I am afraid I haven't got any other idea how to make them invisble through the whole recordset. shrug.gif
Maybe u can post this as a New question, maybe someone else has an idea. Goodluck!
Daniel
Acess_help
Nah you helped great. Thanks once more! Good day to u!
danishani
Okidoki, glad to helped you this far frown.gif
aniel
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.