open selected record from subform in a form for editing

joshi868b

New Member
Joined
Jan 26, 2016
Messages
15
I have a subform which shows the list of record .primary key is not assigned.i want to select a record from subform and want to click on a button called edit.it should open the form with the selected details.thanks in advance . suppose the subform name is" portdetails subform" and filed are l2 ip address, vlan ,mac address,name ,ser no,dn no,.can i attach the database here in this forum .
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Here is an example that I have used in my database. Hopefully it can help you along in yours

in design view select your edit button and under the event table choose the build event on the click event.
I personally use code builder but you could use one of the other options just play with it and see what works best for your.


Code:
Private Sub EditButton_Click()
    DoCmd.OpenForm "myFormName", acNormal, ,(*Where Condition Goes Here)* , , acDialog
End Sub
 
Last edited:
Upvote 0
I am not at my computer right now so it's hard to type. But try taking a look at this video and see if it helps you with your situation

https://youtu.be/RILqSTAAQpM

I started out by watching all of these learn access tutorials so it's a great place for beginners he has play lists that show with vba code and without.

I think that this without vba tutorial should suite your needs.

On a side note to access your form through vba you would need to fully verify it with something like

[Forms]![myFormName]![myTargetField]

You would put something like that in the where clause if I am not mistaken.
 
Upvote 0
I followed that but in my case when we link both the form i didnt find any form on left side .kindly help .is it beacause of primary key i am not having any primary key
 
Upvote 0
Hey man sorry I have been busy these last few days. With out actually knowing your database I cant give a direct answer because any answer might not directly work. But I can try and point you in the right direction. I already have actually but lets try and put things together in one cohesive post.

lets break down what your trying to do and see if we cant come up with a solution.

you want to select a record in a subform and then push a button to have another form open to that record so you can edit it.
1. you will need the original form, a subform (with your record on it) and an edit button to open yet another third form for record editing.

I feel by your description you already have all 3 forms built you just need to know how to get your button to work. (I am still pretty new so I dont know the direct answer but I know enough to give it a shot at a description.)

The first think we need to know how to do is open a form with vba code.
Code:
Private Sub EditButton_Click()     DoCmd.OpenForm "myFormName", acNormal, ,(*Where Condition Goes Here)* , , acDialog
End Sub
That is code I have used before.

you were confused about the where condition so lets break that down a little bit further.

your where condition needs to specify what record you want to edit. So what does that mean.
it means your button needs to get a reference to the sub form that has the focused record and it needs to open the third form filtered to that record.

next you need to ask yourself how to access your subform through code.

to do this you need to qualify the reference. which I posted an example here.

[Forms]![myFormName]![myTargetField]

the first part to this statement is [Forms]!
This is stating you want to access a form from the forms definitions.

![myFormName]
is the name of your subform.
![myTargetField]

is the record that you have selected.

so try and play around with the Intellisense when you write your code and see what pops up.

I would assume you are going to want a statement similar to this

Code:
Private Sub EditButton_Click()     
DoCmd.OpenForm "myFormName", acNormal, ,[Forms]![mySubForm]![selected] , , acDialog
End Sub

it could also be
Code:
Private Sub EditButton_Click()     
DoCmd.OpenForm "myFormName", acNormal, ,[Forms]![mySubForm].selected , , acDialog
End Sub

I always get confused on when to use the ! separator and the . separator.

from what I understand ! is used like accessing different levels of a file system (ie. C:/Users/Admin/...ect)
where the ! is a stand in for the /

the . is used to access files/elements within the folder.

Sorry I cant be more direct help but there is lots of information out there on opening forms you just got to search around a little bit.
Hopefully I have given you enough information to make some additional educated searches to help point you in the right direction.
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,048
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top