G
Guest
Hi,
Probably bnot a good description but I'm finding it hard to put into words
what my requirements are.
I have a form with many labels and one free text field users can key into.
Rather than having a button to 'Update' after completing the comments I was
intending to update after every keystroke. I have been able to do this BUT
the cursor always positions itself at the left-hand side of the text, not at
the end of the last character entered. I have stepped through the code and
just before the Exit Sub the value of Starting_Point is equal to the length
of the text (eg 22) yet the cursor remains at position 1.
I have used the following code:
Private Sub Buying_Office_Comment_Change()
Starting_Point = Me![Buying Office Comment].SelStart
If From_Buying_Office_Comment_Change = True Then
From_Buying_Office_Comment_Change = False
Me![Buying Office Comment].SelStart = Starting_Point
Exit Sub
End If
My_Count = 0
Me![LaybyNo].SetFocus
The_LaybyNo = Me![LaybyNo].Text
Me![ItemCode].SetFocus
The_ItemCode = Me![ItemCode]
The_Concat = The_LaybyNo & The_ItemCode
Me![Buying Office Comment].SetFocus
The_Comment = Me![Buying Office Comment].Text
Call Check_If_There_Is_A_Previous_Comment
DoCmd.SetWarnings False
From_Buying_Office_Comment_Change = False
If The_Count = 0 Then 'No Previous Comment
DoCmd.RunSQL "INSERT INTO Tbl_Rainchecks_Comments(Concat, [Buying
Office Comments], [Buying Office Comments Date]) VALUES ('" & The_Concat &
"', '" & The_Comment & "', now);"
DoCmd.RunSQL "UPDATE Tbl_Rainchecks_Comments SET
Tbl_Rainchecks_Comments.[Buying Office Comments Date] = """ & Now & """ WHERE
((Tbl_Rainchecks_Comments.[Concat])=""" & Me![LaybyNo] & Me![ItemCode] &
""");"
Else
If My_Count = 1 Then Exit Sub
Me![Buying Office Comment].SetFocus
DoCmd.RunSQL "UPDATE Tbl_Rainchecks_Comments SET
Tbl_Rainchecks_Comments.[Buying Office Comments] = """ & The_Comment & """
WHERE ((Tbl_Rainchecks_Comments.[Concat])=""" & Me![LaybyNo] & Me![ItemCode]
& """);"
DoCmd.RunSQL "UPDATE Tbl_Rainchecks_Comments SET
Tbl_Rainchecks_Comments.[Buying Office Comments Date] = """ & Now & """ WHERE
((Tbl_Rainchecks_Comments.[Concat])=""" & Me![LaybyNo] & Me![ItemCode] &
""");"
My_Count = 1
From_Buying_Office_Comment_Change = True
Me![Buying Office Comment Date].SetFocus
Me![Buying Office Comment].SetFocus
Me![Buying Office Comment].Enabled = True
Me![Buying Office Comment].Text = The_Comment
End If
End Sub
Public Sub Check_If_There_Is_A_Previous_Comment()
Me![LaybyNo].SetFocus
The_LaybyNo = Me![LaybyNo].Text
Me![ItemCode].SetFocus
The_ItemCode = Me![ItemCode]
The_Concat = The_LaybyNo & The_ItemCode
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT Tbl_Rainchecks_Comments.Concat,
Tbl_Rainchecks_Comments.[Buying Office Comments],
Tbl_Rainchecks_Comments.[Buying Office Comments Date] FROM
Tbl_Rainchecks_Comments WHERE (((Tbl_Rainchecks_Comments.Concat)='" &
The_Concat & "'));")
The_Count = 0
With rst
Do Until .EOF
The_Count = The_Count + 1
The_Concat = Val(!Concat)
The_Buying_Office_Comments = ![Buying Office Comments]
The_Buying_Office_Comments_Date = ![Buying Office Comments Date]
Me![Buying Office Comment] = The_Buying_Office_Comments
Me![Buying Office Comment Date] = The_Buying_Office_Comments_Date
.MoveNext
Loop
Found_Last:
.Close
End With
End Sub
Probably bnot a good description but I'm finding it hard to put into words
what my requirements are.
I have a form with many labels and one free text field users can key into.
Rather than having a button to 'Update' after completing the comments I was
intending to update after every keystroke. I have been able to do this BUT
the cursor always positions itself at the left-hand side of the text, not at
the end of the last character entered. I have stepped through the code and
just before the Exit Sub the value of Starting_Point is equal to the length
of the text (eg 22) yet the cursor remains at position 1.
I have used the following code:
Private Sub Buying_Office_Comment_Change()
Starting_Point = Me![Buying Office Comment].SelStart
If From_Buying_Office_Comment_Change = True Then
From_Buying_Office_Comment_Change = False
Me![Buying Office Comment].SelStart = Starting_Point
Exit Sub
End If
My_Count = 0
Me![LaybyNo].SetFocus
The_LaybyNo = Me![LaybyNo].Text
Me![ItemCode].SetFocus
The_ItemCode = Me![ItemCode]
The_Concat = The_LaybyNo & The_ItemCode
Me![Buying Office Comment].SetFocus
The_Comment = Me![Buying Office Comment].Text
Call Check_If_There_Is_A_Previous_Comment
DoCmd.SetWarnings False
From_Buying_Office_Comment_Change = False
If The_Count = 0 Then 'No Previous Comment
DoCmd.RunSQL "INSERT INTO Tbl_Rainchecks_Comments(Concat, [Buying
Office Comments], [Buying Office Comments Date]) VALUES ('" & The_Concat &
"', '" & The_Comment & "', now);"
DoCmd.RunSQL "UPDATE Tbl_Rainchecks_Comments SET
Tbl_Rainchecks_Comments.[Buying Office Comments Date] = """ & Now & """ WHERE
((Tbl_Rainchecks_Comments.[Concat])=""" & Me![LaybyNo] & Me![ItemCode] &
""");"
Else
If My_Count = 1 Then Exit Sub
Me![Buying Office Comment].SetFocus
DoCmd.RunSQL "UPDATE Tbl_Rainchecks_Comments SET
Tbl_Rainchecks_Comments.[Buying Office Comments] = """ & The_Comment & """
WHERE ((Tbl_Rainchecks_Comments.[Concat])=""" & Me![LaybyNo] & Me![ItemCode]
& """);"
DoCmd.RunSQL "UPDATE Tbl_Rainchecks_Comments SET
Tbl_Rainchecks_Comments.[Buying Office Comments Date] = """ & Now & """ WHERE
((Tbl_Rainchecks_Comments.[Concat])=""" & Me![LaybyNo] & Me![ItemCode] &
""");"
My_Count = 1
From_Buying_Office_Comment_Change = True
Me![Buying Office Comment Date].SetFocus
Me![Buying Office Comment].SetFocus
Me![Buying Office Comment].Enabled = True
Me![Buying Office Comment].Text = The_Comment
End If
End Sub
Public Sub Check_If_There_Is_A_Previous_Comment()
Me![LaybyNo].SetFocus
The_LaybyNo = Me![LaybyNo].Text
Me![ItemCode].SetFocus
The_ItemCode = Me![ItemCode]
The_Concat = The_LaybyNo & The_ItemCode
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT Tbl_Rainchecks_Comments.Concat,
Tbl_Rainchecks_Comments.[Buying Office Comments],
Tbl_Rainchecks_Comments.[Buying Office Comments Date] FROM
Tbl_Rainchecks_Comments WHERE (((Tbl_Rainchecks_Comments.Concat)='" &
The_Concat & "'));")
The_Count = 0
With rst
Do Until .EOF
The_Count = The_Count + 1
The_Concat = Val(!Concat)
The_Buying_Office_Comments = ![Buying Office Comments]
The_Buying_Office_Comments_Date = ![Buying Office Comments Date]
Me![Buying Office Comment] = The_Buying_Office_Comments
Me![Buying Office Comment Date] = The_Buying_Office_Comments_Date
.MoveNext
Loop
Found_Last:
.Close
End With
End Sub