Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-07-2017, 05:06 AM   #1
hooolagon
Newly Registered User
 
Join Date: May 2017
Posts: 6
Thanks: 2
Thanked 1 Time in 1 Post
hooolagon is on a distinguished road
Repeat Subform last field entry x amount of times using command button

Okay so I have a "table1" and a "table2". Table1 has a primary key autonumber which is one to many into table2, a date and a type field which has two defined lookup options. table2 only has the primary key from table1 as a number input and an ID field which is linked to table3 which contains the ID as a primary key.

So when I created a form for table1 it creates a main form and a subform using table2's only remaining field "ID". Perfect, here I can enter multiple IDs into a single table which creates multiple records automatically in table2.

Now I would like a button that would repeat the ID entry in the subform 5 times, preferably using VBA and I have no idea how to do it,

Once again, repeat the last entered field in the subform 5 times using a button

Thanks
Attached Files
File Type: accdb Repeat Subform 5 Times.accdb (572.0 KB, 48 views)


Last edited by hooolagon; 05-07-2017 at 05:15 AM. Reason: Add database
hooolagon is offline   Reply With Quote
Old 05-07-2017, 10:22 AM   #2
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,317
Thanks: 540
Thanked 940 Times in 891 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Repeat Subform last field entry x amount of times using command button

See Attached:-
Attached Files
File Type: zip Repeat Subform 5 Times.zip (38.7 KB, 60 views)
__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)
Uncle Gizmo is offline   Reply With Quote
The Following User Says Thank You to Uncle Gizmo For This Useful Post:
hooolagon (05-08-2017)
Old 05-08-2017, 02:21 PM   #3
hooolagon
Newly Registered User
 
Join Date: May 2017
Posts: 6
Thanks: 2
Thanked 1 Time in 1 Post
hooolagon is on a distinguished road
Re: Repeat Subform last field entry x amount of times using command button

Thank you, took me a while to understand your genius and implement it! Much appreciated

hooolagon is offline   Reply With Quote
The Following User Says Thank You to hooolagon For This Useful Post:
Uncle Gizmo (05-08-2017)
Old 05-09-2017, 12:55 PM   #4
Uncle Gizmo
Nifty Access Guy
 
Uncle Gizmo's Avatar
 
Join Date: Jul 2003
Location: Newbury Berks UK
Posts: 10,317
Thanks: 540
Thanked 940 Times in 891 Posts
Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough Uncle Gizmo is a jewel in the rough
Send a message via Skype™ to Uncle Gizmo
Re: Repeat Subform last field entry x amount of times using command button

Heres a simpler, but not so flexible method:-

Code:
Private Sub Command13_Click()
Dim X As Integer

    If Not IsNull(Me.subFrmWinT2.Form!txtID) Then
        
        For X = 1 To Me.txtInsertThisMany
            CurrentDb.Execute fSQL_SelectedRecord(Me.subFrmWinT2.Form!txtID)
        Next X
        
        Me.subFrmWinT2.Requery
    Else
        MsgBox " >>> Please Select a Row Containing DATA!!!"
    End If

End Sub

Private Function fSQL_SelectedRecord(lngID As Long) As String

Dim strSQL0 As String
Dim strSQL1 As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strSQL5 As String

strSQL1 = "INSERT INTO Table2 (table1ID, customID ) "
strSQL2 = "SELECT table1ID, customID "
strSQL3 = "FROM Table2 "
strSQL4 = "WHERE (((ID)="
'2
strSQL5 = "));"

strSQL0 = strSQL1 & strSQL2 & strSQL3 & strSQL4 & lngID & strSQL5

fSQL_SelectedRecord = strSQL0

End Function      'fSQL_SelectedRecord

__________________
Code:
                 |||||
               @(~^~)@
-------------oOo---U---oOo-------------
|                                     |
|      Uncle Gizmo              |
|                                     |
|                                     |
| Get $20 worth of "Nifty Code"       |
|      
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
| | Ooo | |_________________ooO____( )________| ( ) ) / \ ( (_/ \_)

Last edited by Uncle Gizmo; 05-10-2017 at 02:15 PM. Reason: unnecessary call removed
Uncle Gizmo is offline   Reply With Quote
Reply

Tags
duplicate , field , multiple times , repeat , subform

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Command Button press multiple times Symon Modules & VBA 21 07-23-2015 08:38 AM
Subform Command Button, based on field npsavidge Forms 9 10-28-2009 06:47 AM
Add XML tags to selected text in memo field located in a subform with command button harleyskater Modules & VBA 2 03-26-2008 02:55 AM
Repeat last entry in combo box field jerrywheels Forms 7 03-21-2007 04:59 AM
Prevent repeat command button click rpadams General 4 03-12-2004 07:17 AM




All times are GMT -8. The time now is 05:32 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World