I'm using access 2007.
I have a mainform and a subform linked properly.
I have a button on my mainform that will insert records to the underlying table of my subform when clicked.
The records are inserted into the table correctly, but they won't display in the subform until I move off the main form.
The underlying table doesn't contain records at the time the button on the mainform is clicked. That's a rule.
I requery the subform at the end of the button click event. It refreshes the subform with data from a previous record.
I don't know how to fix it or what I'm doing wrong.
I insert the records with doCmd.
Any help will be appreciated.
Here's the code from the onclick button event:
Dim myRS As DAO.Recordset
Dim dbs As Database
Dim strSql As String
Dim thefund As Integer
Dim theID As Integer
Dim sql2 As String
Dim calcamt As Currency
Dim thepct As Double
Dim cntrec As Integer
cntrec = 0
theID = Me.contributeID
'theamt = Me.contributeAmount
strSql = "Select * from tithing_Sys_details where titheSystem = " & Me.contributeTithesys & ";"
Set dbs = CurrentDb
Set myRS = dbs.OpenRecordset(strSql)
If Not (myRS.BOF And myRS.EOF) Then
myRS.MoveFirst
Else
MsgBox "Tithing records are missing. Contact Administrator. Allocate contribution manually."
Set myRS = Nothing
Set dbs = Nothing
Exit Sub
End If
Do While Not myRS.EOF
cntrec = cntrec + 1
thefund = myRS!titheFund
thepct = myRS!tithePercent
calcamt = theamt * thepct
'then I need to insert with docmd the allocation record
sql2 = "Insert into allocation_tbl(allocateFund, allocateAmount, allocateContribID, allocatePercent) Values (" & thefund & ", " & calcamt & ", " & theID & ", " & thepct & ");"
DoCmd.SetWarnings False
DoCmd.RunSQL sql2
DoCmd.SetWarnings True
myRS.MoveNext
Loop
MsgBox "tithe records read " & cntrec
Set myRS = Nothing
Set dbs = Nothing
Me.subfrm_Allocation.Requery
I have a mainform and a subform linked properly.
I have a button on my mainform that will insert records to the underlying table of my subform when clicked.
The records are inserted into the table correctly, but they won't display in the subform until I move off the main form.
The underlying table doesn't contain records at the time the button on the mainform is clicked. That's a rule.
I requery the subform at the end of the button click event. It refreshes the subform with data from a previous record.
I don't know how to fix it or what I'm doing wrong.
I insert the records with doCmd.
Any help will be appreciated.
Here's the code from the onclick button event:
Dim myRS As DAO.Recordset
Dim dbs As Database
Dim strSql As String
Dim thefund As Integer
Dim theID As Integer
Dim sql2 As String
Dim calcamt As Currency
Dim thepct As Double
Dim cntrec As Integer
cntrec = 0
theID = Me.contributeID
'theamt = Me.contributeAmount
strSql = "Select * from tithing_Sys_details where titheSystem = " & Me.contributeTithesys & ";"
Set dbs = CurrentDb
Set myRS = dbs.OpenRecordset(strSql)
If Not (myRS.BOF And myRS.EOF) Then
myRS.MoveFirst
Else
MsgBox "Tithing records are missing. Contact Administrator. Allocate contribution manually."
Set myRS = Nothing
Set dbs = Nothing
Exit Sub
End If
Do While Not myRS.EOF
cntrec = cntrec + 1
thefund = myRS!titheFund
thepct = myRS!tithePercent
calcamt = theamt * thepct
'then I need to insert with docmd the allocation record
sql2 = "Insert into allocation_tbl(allocateFund, allocateAmount, allocateContribID, allocatePercent) Values (" & thefund & ", " & calcamt & ", " & theID & ", " & thepct & ");"
DoCmd.SetWarnings False
DoCmd.RunSQL sql2
DoCmd.SetWarnings True
myRS.MoveNext
Loop
MsgBox "tithe records read " & cntrec
Set myRS = Nothing
Set dbs = Nothing
Me.subfrm_Allocation.Requery