dreamdelerium
Registered User.
- Local time
- Today, 14:11
- Joined
- Aug 24, 2007
- Messages
- 88
hi everyone. i was wondering if someone could explain this to me. i have several forms in my access application but only one form is being shown at any given time. i have a macro call a function to check to see which form is open. depending on which form is open i call a different function. all the functions are the same in that they save the values from that form to a corresponding table. each form has a tabcontrol with several pages. the function is something like this:
as you can see, im just trying to save the values from each control into its corresponding table. the problem is that when i do this it will save the values from the previous time i ran the function. the only way ive found to fix this is use this bit of code to change the pages first, then run the docmd.runsql command:
can anyone tell me whats going on?
Code:
Public Function SaveAsNewSection4()
On Error GoTo errorhandler
Dim GetLength As Integer
Dim InsertString, InsertString1 As String
Dim MyNewString As String
Dim q1, GetCode, GetFacility, GetDistrict As String
Dim selectstring, SelectString2 As String
Dim GetLocation, GetType, GetAuthority As String
GetDistrict = FORMS("frmSection1").Controls("DistrictID").Column(2)
GetName = FORMS("frmSection1").Controls("FacilityID").Column(1)
GetLocation = Format(FORMS("frmSection1").Controls("LocationID").Value, "000")
GetType = Format(FORMS("frmSection1").Controls("TypeID").Value, "000")
GetAuthority = Format(FORMS("frmSection1").Controls("AuthorityID").Value, "000")
GetQNumber = Format(FORMS("frmSection1").Controls("QNumber").Value, "000")
GetRecordID = GetDistrict & "-" & GetName & "-" & GetQNumber
For i = 101 To 111
InsertString = InsertString & "Q" & Format(i, "000") & ","
Next i
GetLength = Len(InsertString) - 1
InsertString = Left(InsertString, GetLength)
For i = 101 To 111
InsertString1 = InsertString1 & Replace(Nz(FORMS![frmSection4].Controls("Q" & i).Value, ""), "'", "''") & "','"
Next i
GetLength = Len(InsertString1) - 1
InsertString1 = Left(InsertString1, GetLength)
MyNewString = "Insert into tblSection4 (RecordID,DistrictID,FacilityID,LocationID,TypeID,AuthorityID," & InsertString & ") " _
& "values ('" & GetRecordID & "','" & GetDistrict & "','" & GetName & "','" & GetLocation & "','" & GetType & "','" & GetAuthority & "','" & InsertString1 & ")"
GetLength = Len(MyNewString) - 2
MyNewString = Left(MyNewString, GetLength)
MyNewString = MyNewString & ")"
DoCmd.RunSQL MyNewString
MsgBox ("Section 4 saved")
errorhandler:
If Err.Number = 0 Then
Else
MsgBox Err.Number & " " & Err.Description & " error in BuildMyStringForm1 function"
End If
end sub
as you can see, im just trying to save the values from each control into its corresponding table. the problem is that when i do this it will save the values from the previous time i ran the function. the only way ive found to fix this is use this bit of code to change the pages first, then run the docmd.runsql command:
Code:
FORMS("frmSection4").Controls("TabCtl1782").Pages.Item("Page 01").SetFocus
FORMS("frmSection4").Controls("TabCtl1782").Pages.Item("Page 02").SetFocus
FORMS("frmSection4").Controls("TabCtl1782").Pages.Item("Page 01").SetFocus
can anyone tell me whats going on?