Leave trailing spaces

G

Guest

Is there any way to make access leave a trailing space as it exits (or
enters) a text field?

I have a search text box, that runs a filter as the user types in a part
number, checks to see if any records match, beep's and reverts to .oldvalue
if not, or allows more typing whilst sub-sorting the parts list.
Unfortunatley, this filtering forces access to exit and re-enter the same
field, which trims the trailing space, meaning any parts separated by spaces
cannot be sub-searched.

thanks,

TonyT..
 
J

Jeff Boyce

As far as I know, Access trims trailing spaces.

Have you tried searching using:
Like * & [Enter search term] & *


Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

Guest

Based on the description of what you are doing, it appears to me a Combo box
would be a better control to use for this.
 
G

Guest

thanks for responses,

I should explain that the textbox in question is in the Form Header of a
continuous form showing the entire parts list (users stock, 8000+ lines this
particular user), the part numbers follow no particular format as they cover
many manufacturers. So I have set up the textbox to filter the parts list
(On_Change event) as they type the start of the part number.

Don't think a combobox would make any difference would it? As access seems
to force a *silent* focus move from said textbox back to it again, without
the focus *actually* being anywhere else between-times.

Hope this explains better,

TonyT..
 
G

Guest

The native behavior of a combo box is what you are writing code to do with a
text box. It would be less code and, I think (without actually testing) it
would be faster. I don't really see any reason a combo box would not be a
better solution.
 
J

John W. Vinson

The native behavior of a combo box is what you are writing code to do with a
text box. It would be less code and, I think (without actually testing) it
would be faster. I don't really see any reason a combo box would not be a
better solution.

The only "gotcha" I can think of is if there are more than 65,536 parts in the
list (the limit for the number of records displayed in a combo).

John W. Vinson [MVP]
 
G

Guest

John W. Vinson said:
The only "gotcha" I can think of is if there are more than 65,536 parts in the
list (the limit for the number of records displayed in a combo).

John W. Vinson [MVP]

Seems to work fine with exactly the same code as I had originally with a
textbox, whilst leaving the cbo unbound with no rowsource at all.
Surely this will nullify the 65,536 limit too! Or am I missing something?

thanks to both you and mostly Klatuu :/

TonyT..
 
G

Guest

The cbo does need a row source. It should be a query based on the part
number. By bound, I meant bound to the form's recordset.
 
G

Guest

I have it working exactly as I want, reducing the 8000 or so parts in the
continuous part of the form down as I type each character into the combobox,
without a rowsource & unbound. The code is identical to how I had it with the
textbox, but by virtue of being a combobox (I guess) the focus never leaves
the cbo so the trailing spaces don't get trimmed.

Inspired! (even if it wasn't what you had in mind) :p

TonyT..
 
G

Guest

Great!
Would you do us a favor and post the code. I would like to see how that
works.

Thanks,
 
G

Guest

Excuse the poor coding, only at mock up stage!!

Private Sub cboPtFilt_Change()
Dim strFilt1 As String
Dim strOldVal As String

On Error Resume Next

If Not IsNull(Me![cboPtFilt].Text) Then
If Not IsNull(Me![cboPtFilt].OldValue) Then
strOldVal = Me![cboPtFilt].OldValue
Else: strOldVal = ""
End If
sglStrCnt = Len(Me![cboPtFilt].Text)
strFilt1 = Me![cboPtFilt].Text
'Me.FilterOn = False
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
Me.FilterOn = True
If Me.RecordsetClone.RecordCount < 1 Then
If strOldVal <> "" Then
Me![cboPtFilt] = strOldVal
sglStrCnt = Len(strOldVal)
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
Beep
Me![Text34] = ""
Me![Text39] = ""
Me.Refresh
Else:
Me![cboPtFilt] = strOldVal
Me.FilterOn = False
Me![Text34] = ""
Me![Text39] = ""
strPtFilt = "pttbl.ptnum = '*'"
Beep
Me.Refresh
End If
End If
End If

Me![Text34] = ""
Me![Text39] = ""
strDesc = "*"
strDesc2 = "*"

Me![cboPtFilt].SetFocus
Me![cboPtFilt].SelStart = sglStrCnt

On Error GoTo 0
End Sub


Text34 & text39 are further search fields based on description rather than
part numbers.

Now it works time to sit down and code it properley (and *alot* more
efficiently)

thanks again,

TonyT..
 
G

Guest

Thanks, Tony.
Interesting approach.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
Excuse the poor coding, only at mock up stage!!

Private Sub cboPtFilt_Change()
Dim strFilt1 As String
Dim strOldVal As String

On Error Resume Next

If Not IsNull(Me![cboPtFilt].Text) Then
If Not IsNull(Me![cboPtFilt].OldValue) Then
strOldVal = Me![cboPtFilt].OldValue
Else: strOldVal = ""
End If
sglStrCnt = Len(Me![cboPtFilt].Text)
strFilt1 = Me![cboPtFilt].Text
'Me.FilterOn = False
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
Me.FilterOn = True
If Me.RecordsetClone.RecordCount < 1 Then
If strOldVal <> "" Then
Me![cboPtFilt] = strOldVal
sglStrCnt = Len(strOldVal)
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
Beep
Me![Text34] = ""
Me![Text39] = ""
Me.Refresh
Else:
Me![cboPtFilt] = strOldVal
Me.FilterOn = False
Me![Text34] = ""
Me![Text39] = ""
strPtFilt = "pttbl.ptnum = '*'"
Beep
Me.Refresh
End If
End If
End If

Me![Text34] = ""
Me![Text39] = ""
strDesc = "*"
strDesc2 = "*"

Me![cboPtFilt].SetFocus
Me![cboPtFilt].SelStart = sglStrCnt

On Error GoTo 0
End Sub


Text34 & text39 are further search fields based on description rather than
part numbers.

Now it works time to sit down and code it properley (and *alot* more
efficiently)

thanks again,

TonyT..
Klatuu said:
Great!
Would you do us a favor and post the code. I would like to see how that
works.

Thanks,
 
G

Guest

Was formed out of trying many different approacheas at getting round my
original trailing space problem, now I can't see the wood for the trees :/

What approach would you suggest / consider more normal for this type of
application?

TonyT..

Klatuu said:
Thanks, Tony.
Interesting approach.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
Excuse the poor coding, only at mock up stage!!

Private Sub cboPtFilt_Change()
Dim strFilt1 As String
Dim strOldVal As String

On Error Resume Next

If Not IsNull(Me![cboPtFilt].Text) Then
If Not IsNull(Me![cboPtFilt].OldValue) Then
strOldVal = Me![cboPtFilt].OldValue
Else: strOldVal = ""
End If
sglStrCnt = Len(Me![cboPtFilt].Text)
strFilt1 = Me![cboPtFilt].Text
'Me.FilterOn = False
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
Me.FilterOn = True
If Me.RecordsetClone.RecordCount < 1 Then
If strOldVal <> "" Then
Me![cboPtFilt] = strOldVal
sglStrCnt = Len(strOldVal)
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
Beep
Me![Text34] = ""
Me![Text39] = ""
Me.Refresh
Else:
Me![cboPtFilt] = strOldVal
Me.FilterOn = False
Me![Text34] = ""
Me![Text39] = ""
strPtFilt = "pttbl.ptnum = '*'"
Beep
Me.Refresh
End If
End If
End If

Me![Text34] = ""
Me![Text39] = ""
strDesc = "*"
strDesc2 = "*"

Me![cboPtFilt].SetFocus
Me![cboPtFilt].SelStart = sglStrCnt

On Error GoTo 0
End Sub


Text34 & text39 are further search fields based on description rather than
part numbers.

Now it works time to sit down and code it properley (and *alot* more
efficiently)

thanks again,

TonyT..
Klatuu said:
Great!
Would you do us a favor and post the code. I would like to see how that
works.

Thanks,
--
Dave Hargis, Microsoft Access MVP


:

I have it working exactly as I want, reducing the 8000 or so parts in the
continuous part of the form down as I type each character into the combobox,
without a rowsource & unbound. The code is identical to how I had it with the
textbox, but by virtue of being a combobox (I guess) the focus never leaves
the cbo so the trailing spaces don't get trimmed.

Inspired! (even if it wasn't what you had in mind) :p

TonyT..

:

The cbo does need a row source. It should be a query based on the part
number. By bound, I meant bound to the form's recordset.
--
Dave Hargis, Microsoft Access MVP


:



:

The native behavior of a combo box is what you are writing code to do with a
text box. It would be less code and, I think (without actually testing) it
would be faster. I don't really see any reason a combo box would not be a
better solution.

The only "gotcha" I can think of is if there are more than 65,536 parts in the
list (the limit for the number of records displayed in a combo).

John W. Vinson [MVP]


Seems to work fine with exactly the same code as I had originally with a
textbox, whilst leaving the cbo unbound with no rowsource at all.
Surely this will nullify the 65,536 limit too! Or am I missing something?

thanks to both you and mostly Klatuu :/

TonyT..
 
G

Guest

I haven't had time to look at your code in detail, but I still think the
combo box is the best way, but I can't remember if you said why you can't use
a combo.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
Was formed out of trying many different approacheas at getting round my
original trailing space problem, now I can't see the wood for the trees :/

What approach would you suggest / consider more normal for this type of
application?

TonyT..

Klatuu said:
Thanks, Tony.
Interesting approach.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
Excuse the poor coding, only at mock up stage!!

Private Sub cboPtFilt_Change()
Dim strFilt1 As String
Dim strOldVal As String

On Error Resume Next

If Not IsNull(Me![cboPtFilt].Text) Then
If Not IsNull(Me![cboPtFilt].OldValue) Then
strOldVal = Me![cboPtFilt].OldValue
Else: strOldVal = ""
End If
sglStrCnt = Len(Me![cboPtFilt].Text)
strFilt1 = Me![cboPtFilt].Text
'Me.FilterOn = False
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
Me.FilterOn = True
If Me.RecordsetClone.RecordCount < 1 Then
If strOldVal <> "" Then
Me![cboPtFilt] = strOldVal
sglStrCnt = Len(strOldVal)
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
Beep
Me![Text34] = ""
Me![Text39] = ""
Me.Refresh
Else:
Me![cboPtFilt] = strOldVal
Me.FilterOn = False
Me![Text34] = ""
Me![Text39] = ""
strPtFilt = "pttbl.ptnum = '*'"
Beep
Me.Refresh
End If
End If
End If

Me![Text34] = ""
Me![Text39] = ""
strDesc = "*"
strDesc2 = "*"

Me![cboPtFilt].SetFocus
Me![cboPtFilt].SelStart = sglStrCnt

On Error GoTo 0
End Sub


Text34 & text39 are further search fields based on description rather than
part numbers.

Now it works time to sit down and code it properley (and *alot* more
efficiently)

thanks again,

TonyT..
:

Great!
Would you do us a favor and post the code. I would like to see how that
works.

Thanks,
--
Dave Hargis, Microsoft Access MVP


:

I have it working exactly as I want, reducing the 8000 or so parts in the
continuous part of the form down as I type each character into the combobox,
without a rowsource & unbound. The code is identical to how I had it with the
textbox, but by virtue of being a combobox (I guess) the focus never leaves
the cbo so the trailing spaces don't get trimmed.

Inspired! (even if it wasn't what you had in mind) :p

TonyT..

:

The cbo does need a row source. It should be a query based on the part
number. By bound, I meant bound to the form's recordset.
--
Dave Hargis, Microsoft Access MVP


:



:

The native behavior of a combo box is what you are writing code to do with a
text box. It would be less code and, I think (without actually testing) it
would be faster. I don't really see any reason a combo box would not be a
better solution.

The only "gotcha" I can think of is if there are more than 65,536 parts in the
list (the limit for the number of records displayed in a combo).

John W. Vinson [MVP]


Seems to work fine with exactly the same code as I had originally with a
textbox, whilst leaving the cbo unbound with no rowsource at all.
Surely this will nullify the 65,536 limit too! Or am I missing something?

thanks to both you and mostly Klatuu :/

TonyT..
 
G

Guest

I am now using a combo as per your earlier reply, I guess I was wondering how
your approach using a combobox with a rowsource would work to filter the data
compared to my version of coding with no rowsource.

TonyT..


Klatuu said:
I haven't had time to look at your code in detail, but I still think the
combo box is the best way, but I can't remember if you said why you can't use
a combo.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
Was formed out of trying many different approacheas at getting round my
original trailing space problem, now I can't see the wood for the trees :/

What approach would you suggest / consider more normal for this type of
application?

TonyT..

Klatuu said:
Thanks, Tony.
Interesting approach.
--
Dave Hargis, Microsoft Access MVP


:

Excuse the poor coding, only at mock up stage!!

Private Sub cboPtFilt_Change()
Dim strFilt1 As String
Dim strOldVal As String

On Error Resume Next

If Not IsNull(Me![cboPtFilt].Text) Then
If Not IsNull(Me![cboPtFilt].OldValue) Then
strOldVal = Me![cboPtFilt].OldValue
Else: strOldVal = ""
End If
sglStrCnt = Len(Me![cboPtFilt].Text)
strFilt1 = Me![cboPtFilt].Text
'Me.FilterOn = False
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
Me.FilterOn = True
If Me.RecordsetClone.RecordCount < 1 Then
If strOldVal <> "" Then
Me![cboPtFilt] = strOldVal
sglStrCnt = Len(strOldVal)
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
Beep
Me![Text34] = ""
Me![Text39] = ""
Me.Refresh
Else:
Me![cboPtFilt] = strOldVal
Me.FilterOn = False
Me![Text34] = ""
Me![Text39] = ""
strPtFilt = "pttbl.ptnum = '*'"
Beep
Me.Refresh
End If
End If
End If

Me![Text34] = ""
Me![Text39] = ""
strDesc = "*"
strDesc2 = "*"

Me![cboPtFilt].SetFocus
Me![cboPtFilt].SelStart = sglStrCnt

On Error GoTo 0
End Sub


Text34 & text39 are further search fields based on description rather than
part numbers.

Now it works time to sit down and code it properley (and *alot* more
efficiently)

thanks again,

TonyT..
:

Great!
Would you do us a favor and post the code. I would like to see how that
works.

Thanks,
--
Dave Hargis, Microsoft Access MVP


:

I have it working exactly as I want, reducing the 8000 or so parts in the
continuous part of the form down as I type each character into the combobox,
without a rowsource & unbound. The code is identical to how I had it with the
textbox, but by virtue of being a combobox (I guess) the focus never leaves
the cbo so the trailing spaces don't get trimmed.

Inspired! (even if it wasn't what you had in mind) :p

TonyT..

:

The cbo does need a row source. It should be a query based on the part
number. By bound, I meant bound to the form's recordset.
--
Dave Hargis, Microsoft Access MVP


:



:

The native behavior of a combo box is what you are writing code to do with a
text box. It would be less code and, I think (without actually testing) it
would be faster. I don't really see any reason a combo box would not be a
better solution.

The only "gotcha" I can think of is if there are more than 65,536 parts in the
list (the limit for the number of records displayed in a combo).

John W. Vinson [MVP]


Seems to work fine with exactly the same code as I had originally with a
textbox, whilst leaving the cbo unbound with no rowsource at all.
Surely this will nullify the 65,536 limit too! Or am I missing something?

thanks to both you and mostly Klatuu :/

TonyT..
 
G

Guest

The only difficulty you may have with the combo is how long it will take to
open or requery the form. A very large rowsource for the combo could impact
that. You would just have to experiment with it.
If it is too slow to open, you might have a look at Allen Browne's site I
posted earlier. But, 8000 is not a large number of records and all you
should be pulling is the part number and if it is not the primary key, then
the part number and the primary key. Of course, you may also want the part
description, and ......

All I need is this Thermos bottle
All I need is this Thermos bottle and this lamp
Steve Martin - The Jerk.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
I am now using a combo as per your earlier reply, I guess I was wondering how
your approach using a combobox with a rowsource would work to filter the data
compared to my version of coding with no rowsource.

TonyT..


Klatuu said:
I haven't had time to look at your code in detail, but I still think the
combo box is the best way, but I can't remember if you said why you can't use
a combo.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
Was formed out of trying many different approacheas at getting round my
original trailing space problem, now I can't see the wood for the trees :/

What approach would you suggest / consider more normal for this type of
application?

TonyT..

:

Thanks, Tony.
Interesting approach.
--
Dave Hargis, Microsoft Access MVP


:

Excuse the poor coding, only at mock up stage!!

Private Sub cboPtFilt_Change()
Dim strFilt1 As String
Dim strOldVal As String

On Error Resume Next

If Not IsNull(Me![cboPtFilt].Text) Then
If Not IsNull(Me![cboPtFilt].OldValue) Then
strOldVal = Me![cboPtFilt].OldValue
Else: strOldVal = ""
End If
sglStrCnt = Len(Me![cboPtFilt].Text)
strFilt1 = Me![cboPtFilt].Text
'Me.FilterOn = False
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
Me.FilterOn = True
If Me.RecordsetClone.RecordCount < 1 Then
If strOldVal <> "" Then
Me![cboPtFilt] = strOldVal
sglStrCnt = Len(strOldVal)
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
Beep
Me![Text34] = ""
Me![Text39] = ""
Me.Refresh
Else:
Me![cboPtFilt] = strOldVal
Me.FilterOn = False
Me![Text34] = ""
Me![Text39] = ""
strPtFilt = "pttbl.ptnum = '*'"
Beep
Me.Refresh
End If
End If
End If

Me![Text34] = ""
Me![Text39] = ""
strDesc = "*"
strDesc2 = "*"

Me![cboPtFilt].SetFocus
Me![cboPtFilt].SelStart = sglStrCnt

On Error GoTo 0
End Sub


Text34 & text39 are further search fields based on description rather than
part numbers.

Now it works time to sit down and code it properley (and *alot* more
efficiently)

thanks again,

TonyT..
:

Great!
Would you do us a favor and post the code. I would like to see how that
works.

Thanks,
--
Dave Hargis, Microsoft Access MVP


:

I have it working exactly as I want, reducing the 8000 or so parts in the
continuous part of the form down as I type each character into the combobox,
without a rowsource & unbound. The code is identical to how I had it with the
textbox, but by virtue of being a combobox (I guess) the focus never leaves
the cbo so the trailing spaces don't get trimmed.

Inspired! (even if it wasn't what you had in mind) :p

TonyT..

:

The cbo does need a row source. It should be a query based on the part
number. By bound, I meant bound to the form's recordset.
--
Dave Hargis, Microsoft Access MVP


:



:

The native behavior of a combo box is what you are writing code to do with a
text box. It would be less code and, I think (without actually testing) it
would be faster. I don't really see any reason a combo box would not be a
better solution.

The only "gotcha" I can think of is if there are more than 65,536 parts in the
list (the limit for the number of records displayed in a combo).

John W. Vinson [MVP]


Seems to work fine with exactly the same code as I had originally with a
textbox, whilst leaving the cbo unbound with no rowsource at all.
Surely this will nullify the 65,536 limit too! Or am I missing something?

thanks to both you and mostly Klatuu :/

TonyT..
 
G

Guest

Think I'll stick with no rowsource then, one user had over 24,000 lines last
year, so probably nearer 30,000 by now.

TonyT..


Klatuu said:
The only difficulty you may have with the combo is how long it will take to
open or requery the form. A very large rowsource for the combo could impact
that. You would just have to experiment with it.
If it is too slow to open, you might have a look at Allen Browne's site I
posted earlier. But, 8000 is not a large number of records and all you
should be pulling is the part number and if it is not the primary key, then
the part number and the primary key. Of course, you may also want the part
description, and ......

All I need is this Thermos bottle
All I need is this Thermos bottle and this lamp
Steve Martin - The Jerk.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
I am now using a combo as per your earlier reply, I guess I was wondering how
your approach using a combobox with a rowsource would work to filter the data
compared to my version of coding with no rowsource.

TonyT..


Klatuu said:
I haven't had time to look at your code in detail, but I still think the
combo box is the best way, but I can't remember if you said why you can't use
a combo.
--
Dave Hargis, Microsoft Access MVP


:

Was formed out of trying many different approacheas at getting round my
original trailing space problem, now I can't see the wood for the trees :/

What approach would you suggest / consider more normal for this type of
application?

TonyT..

:

Thanks, Tony.
Interesting approach.
--
Dave Hargis, Microsoft Access MVP


:

Excuse the poor coding, only at mock up stage!!

Private Sub cboPtFilt_Change()
Dim strFilt1 As String
Dim strOldVal As String

On Error Resume Next

If Not IsNull(Me![cboPtFilt].Text) Then
If Not IsNull(Me![cboPtFilt].OldValue) Then
strOldVal = Me![cboPtFilt].OldValue
Else: strOldVal = ""
End If
sglStrCnt = Len(Me![cboPtFilt].Text)
strFilt1 = Me![cboPtFilt].Text
'Me.FilterOn = False
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
Me.FilterOn = True
If Me.RecordsetClone.RecordCount < 1 Then
If strOldVal <> "" Then
Me![cboPtFilt] = strOldVal
sglStrCnt = Len(strOldVal)
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
Beep
Me![Text34] = ""
Me![Text39] = ""
Me.Refresh
Else:
Me![cboPtFilt] = strOldVal
Me.FilterOn = False
Me![Text34] = ""
Me![Text39] = ""
strPtFilt = "pttbl.ptnum = '*'"
Beep
Me.Refresh
End If
End If
End If

Me![Text34] = ""
Me![Text39] = ""
strDesc = "*"
strDesc2 = "*"

Me![cboPtFilt].SetFocus
Me![cboPtFilt].SelStart = sglStrCnt

On Error GoTo 0
End Sub


Text34 & text39 are further search fields based on description rather than
part numbers.

Now it works time to sit down and code it properley (and *alot* more
efficiently)

thanks again,

TonyT..
:

Great!
Would you do us a favor and post the code. I would like to see how that
works.

Thanks,
--
Dave Hargis, Microsoft Access MVP


:

I have it working exactly as I want, reducing the 8000 or so parts in the
continuous part of the form down as I type each character into the combobox,
without a rowsource & unbound. The code is identical to how I had it with the
textbox, but by virtue of being a combobox (I guess) the focus never leaves
the cbo so the trailing spaces don't get trimmed.

Inspired! (even if it wasn't what you had in mind) :p

TonyT..

:

The cbo does need a row source. It should be a query based on the part
number. By bound, I meant bound to the form's recordset.
--
Dave Hargis, Microsoft Access MVP


:



:

The native behavior of a combo box is what you are writing code to do with a
text box. It would be less code and, I think (without actually testing) it
would be faster. I don't really see any reason a combo box would not be a
better solution.

The only "gotcha" I can think of is if there are more than 65,536 parts in the
list (the limit for the number of records displayed in a combo).

John W. Vinson [MVP]


Seems to work fine with exactly the same code as I had originally with a
textbox, whilst leaving the cbo unbound with no rowsource at all.
Surely this will nullify the 65,536 limit too! Or am I missing something?

thanks to both you and mostly Klatuu :/

TonyT..
 
G

Guest

okay, I remember you saying 8000.
I would try it with a row source and if the performance is not satisfactory,
then I would try Allen Browne's technique.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
Think I'll stick with no rowsource then, one user had over 24,000 lines last
year, so probably nearer 30,000 by now.

TonyT..


Klatuu said:
The only difficulty you may have with the combo is how long it will take to
open or requery the form. A very large rowsource for the combo could impact
that. You would just have to experiment with it.
If it is too slow to open, you might have a look at Allen Browne's site I
posted earlier. But, 8000 is not a large number of records and all you
should be pulling is the part number and if it is not the primary key, then
the part number and the primary key. Of course, you may also want the part
description, and ......

All I need is this Thermos bottle
All I need is this Thermos bottle and this lamp
Steve Martin - The Jerk.
--
Dave Hargis, Microsoft Access MVP


TonyT said:
I am now using a combo as per your earlier reply, I guess I was wondering how
your approach using a combobox with a rowsource would work to filter the data
compared to my version of coding with no rowsource.

TonyT..


:

I haven't had time to look at your code in detail, but I still think the
combo box is the best way, but I can't remember if you said why you can't use
a combo.
--
Dave Hargis, Microsoft Access MVP


:

Was formed out of trying many different approacheas at getting round my
original trailing space problem, now I can't see the wood for the trees :/

What approach would you suggest / consider more normal for this type of
application?

TonyT..

:

Thanks, Tony.
Interesting approach.
--
Dave Hargis, Microsoft Access MVP


:

Excuse the poor coding, only at mock up stage!!

Private Sub cboPtFilt_Change()
Dim strFilt1 As String
Dim strOldVal As String

On Error Resume Next

If Not IsNull(Me![cboPtFilt].Text) Then
If Not IsNull(Me![cboPtFilt].OldValue) Then
strOldVal = Me![cboPtFilt].OldValue
Else: strOldVal = ""
End If
sglStrCnt = Len(Me![cboPtFilt].Text)
strFilt1 = Me![cboPtFilt].Text
'Me.FilterOn = False
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" & strFilt1 &
"'"
Me.FilterOn = True
If Me.RecordsetClone.RecordCount < 1 Then
If strOldVal <> "" Then
Me![cboPtFilt] = strOldVal
sglStrCnt = Len(strOldVal)
Me.Filter = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
strPtFilt = "left(PtTbl.PtNum, " & sglStrCnt & ") = '" &
strOldVal & "'"
Beep
Me![Text34] = ""
Me![Text39] = ""
Me.Refresh
Else:
Me![cboPtFilt] = strOldVal
Me.FilterOn = False
Me![Text34] = ""
Me![Text39] = ""
strPtFilt = "pttbl.ptnum = '*'"
Beep
Me.Refresh
End If
End If
End If

Me![Text34] = ""
Me![Text39] = ""
strDesc = "*"
strDesc2 = "*"

Me![cboPtFilt].SetFocus
Me![cboPtFilt].SelStart = sglStrCnt

On Error GoTo 0
End Sub


Text34 & text39 are further search fields based on description rather than
part numbers.

Now it works time to sit down and code it properley (and *alot* more
efficiently)

thanks again,

TonyT..
:

Great!
Would you do us a favor and post the code. I would like to see how that
works.

Thanks,
--
Dave Hargis, Microsoft Access MVP


:

I have it working exactly as I want, reducing the 8000 or so parts in the
continuous part of the form down as I type each character into the combobox,
without a rowsource & unbound. The code is identical to how I had it with the
textbox, but by virtue of being a combobox (I guess) the focus never leaves
the cbo so the trailing spaces don't get trimmed.

Inspired! (even if it wasn't what you had in mind) :p

TonyT..

:

The cbo does need a row source. It should be a query based on the part
number. By bound, I meant bound to the form's recordset.
--
Dave Hargis, Microsoft Access MVP


:



:

The native behavior of a combo box is what you are writing code to do with a
text box. It would be less code and, I think (without actually testing) it
would be faster. I don't really see any reason a combo box would not be a
better solution.

The only "gotcha" I can think of is if there are more than 65,536 parts in the
list (the limit for the number of records displayed in a combo).

John W. Vinson [MVP]


Seems to work fine with exactly the same code as I had originally with a
textbox, whilst leaving the cbo unbound with no rowsource at all.
Surely this will nullify the 65,536 limit too! Or am I missing something?

thanks to both you and mostly Klatuu :/

TonyT..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top