copy data from main table to sub data (1 Viewer)

qupe

Registered User.
Local time
Today, 06:02
Joined
Feb 15, 2016
Messages
51
hi
i have main table called tblseries and sub table called tblseason and they have relation between both, i made a form from the main table and in the same form is shows the sub form on the left,

this form has button if i press it, it copy the data from main record and put it as new record in the sub form (sub table), which related to the main record,
from series_name to season_name.

main table : tbleseries
filed : series_name

sub table: tbleseason
filed :season_name

and i wrote this code.
Code:
Private Sub Command17_Click()

 If tblseason_Subform.Form.Dirty Then
        tblseason_Subform.Form.Dirty = False
 End If
 
tblseason_Subform.SetFocus
 
 DoCmd.GoToRecord , , acNewRec
 
 [tblseason_Subform].[Form].[season_name] = Form_tblemain.series_name.Value

End Sub

do you think it is good? or there is more professional code ?
i appreciate any help
 

isladogs

MVP / VIP
Local time
Today, 14:02
Joined
Jan 14, 2017
Messages
18,211
The obvious question is why do you want to copy data from one table to another. In a well designed db, data should be stored in one place only.

Having said that ...
IF there is a good reason to copy it and assuming the code you gave actually works , you can simplify it.

I assume the command button is in your main form so replace the reference to that form with Me.

Perhaps it can be streamlined further

Also it would be easier to code & read if you got rid of underscores in field names: e.g. SeriesName is better than series_name
 

qupe

Registered User.
Local time
Today, 06:02
Joined
Feb 15, 2016
Messages
51
The obvious question is why do you want to copy data from one table to another.

because when i watch a series - as you know series has seasons - usually series start with season 1 which i put in the main record, then when i want to see season 2, season 1 will transfer to sub table, and i will fill the season 2 information.

the last season will be the main record and old ones will be in the sub table.

or do you suggest new way to arrange me data?


i appreciate your suggestion for naming fields
 

isladogs

MVP / VIP
Local time
Today, 14:02
Joined
Jan 14, 2017
Messages
18,211
Well personally I'd just put the info for all series in one table & then use a query to get the info you want for the latest series.

Much simpler to manage
 

Users who are viewing this thread

Top Bottom