can't get edit button to work in subform

raistlin

Registered User.
Local time
Today, 04:07
Joined
Feb 7, 2008
Messages
20
i have a tab control set up on my main form and on one tab i have it set up to add records, on another tab i have a subform on it linked to my search form, and another tab with a subform linked to my edit form.

previously i just had all the forms separate and i was able to set up an edit button on my search form which used this code to open my edit form with the record that i had selected (this code worked);

DoCmd.OpenForm "frmEdit", acNormal, , "[AssetID]=" & Me!AssetID

i didn't like it opening a bunch of different windows all the time, so i combined the forms into one form with the tab control, but now i can't get my edit button to work. depending on the codes i've tried, it either comes up with an error, or will actuall open my frmEdit tab and just place the very first record in it to be edited instead of the one i want to edit. here is the code i currently have that does not work;

DoCmd.GoToControl "tabEdit"
DoCmd.GoToRecord , , acGoTo, "[AssetID]=" & Me!AssetID

all the searches i've done for GoToRecord gives me codes that are similar to my first code which opens up a different form and doesn't work the way i'm wanting it to.

my main form is frmAssets. the tab control is named tabControl, and the individual tabs on that are tabAssests, tabSearch, and tabEdit. the subforms are called frmSearch and frmEdit, which is the same names as the actual forms that they're linked to. how can i get my edit button to open tabEdit and display the record i have chosen from my frmSearch in the tabSearch tab?

here's a watered down version of my db that shows what i have set up for it.
 

Attachments

It's probably treating your number as a string and trying to filter a number field as a string field.

This is what I would try. Make sure your ID field is named txtID, or something like that. You als need to make sure that your tab control is named tabMain, that the frmEdit object on that tab is named frmEdit and not something else.

This also assumes a tab control with 2 pages, the first tab being the frmAssets tab, and the second tab being frmEdit.

Remember that numbering starts at 0 so Page 1 in code is actually Page 2 on your form.

Private Sub cmdEdit_Click()

Dim intID As Integer

If IsNull(txtID.Value) Then

Exit Sub

End If

intID = CInt(txtID.Value)

[Forms]![frmMain].[tabMain].Pages(1).SetFocus
[Forms]![frmMain].[frmEdit].Form.Filter = "[AssetID] = " & intID
[Forms]![frmMain].[frmEdit].Form.FilterOn = True

End Sub
 
works perfect :D

thank you very much for the help.
 

Users who are viewing this thread

Back
Top Bottom