funny thing with tab controls (1 Viewer)

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:
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?
 

wazz

Super Moderator
Local time
Tomorrow, 05:11
Joined
Jun 29, 2004
Messages
1,711
it could be a value issue. i just skimmed over what you have there but you should be aware that .Value (generally) refers to the saved entry in a control and .Text refers to the unsaved entry.

also i have noticed that if you are going to refer to a property of a control such as .Text or .Value then you do have to set focus to the control first.
 

missinglinq

AWF VIP
Local time
Today, 17:11
Joined
Jun 20, 2003
Messages
6,423
...i have noticed that if you are going to refer to a property of a control such as .Text or .Value then you do have to set focus to the control first.

Half right! A control does have to have focus in order to reference its Text property, but does not have to have focus to reference its Value property. Which is why Text is very rarely used.
 

wazz

Super Moderator
Local time
Tomorrow, 05:11
Joined
Jun 29, 2004
Messages
1,711
thanks. i was about to add that but felt unsure for some reason. we always use

if isnull(me.txtSoAndSo) then
or
if me.txtSoAndSo = x then

without using '.value'. .value is the default.
 

dreamdelerium

Registered User.
Local time
Today, 14:11
Joined
Aug 24, 2007
Messages
88
so, does this mean i should use .text or .value. if i use .value how do i get the current value and not the saved one?
 

wazz

Super Moderator
Local time
Tomorrow, 05:11
Joined
Jun 29, 2004
Messages
1,711
i've been assuming your forms are unbound, otherwise there's no need to "physically" save everything the way you are - it would be automatic. if they are unbound then, for textboxes you'll have to use set focus, check for null and .text; for cboboxes i think you just have to check for null (assuming selections are made from a list). basically.
 

Users who are viewing this thread

Top Bottom