Group:  Microsoft Access ยป microsoft.public.access.gettingstarted
Thread: Trim function

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Trim function
"Bre-x" <cholotron[ at ]hotmail.com> 09.08.2006 19:05:03
Is there a way to use VBA to trim and entire record?

I have a table that has 37 columns, each column need to be "trim"
I know that I can create a update query, but I would be really handy if VBA
can be use it.

Regards,

Bre-x


Re: Trim function
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> 09.08.2006 19:19:38
Can you give an example of what you're trying to do?

In general, it's almost always more efficient to use SQL rather than VBA if
it's possible to do the same thing either way.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Bre-x" <cholotron[ at ]hotmail.com> wrote in message
news:u6aTja%23uGHA.1504[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
> Is there a way to use VBA to trim and entire record?
>
> I have a table that has 37 columns, each column need to be "trim"
> I know that I can create a update query, but I would be really handy if
VBA
> can be use it.
>
> Regards,
>
> Bre-x
>
>


Re: Trim function
"Bre-x" <cholotron[ at ]hotmail.com> 09.08.2006 20:15:44
I am dowloading some records (sales orders) from a Pervasive SQL server, the
table has the following fields

SO, double
CUSCOD, text
SODESC, text

ratter than doing a query like this:

DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE BKARINV SET BKARINV.CUSCOD = [BKARINV]![CUSCOD],
BKARINV.SODESC = [BKARINV]![SODESC];"
DoCmd.SetWarnings True

I would like to have a vba code, the BKARINV table has 37 columns (would be
a longggggg query)

Why?? Pervasive fills in the entire field. Example:

The CUSCODE 's field lenght is 15 characters, but if you enter "JOHN",
eventhough "JOHN" has only 4 characters
Pervasive fill the rest with something!!! The only way to clear that
"something" is by using the Trim funcion.

Thanks for your time.

Regards,

Bre-x






"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> wrote in message
news:ukswDj%23uGHA.4752[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text]
> Can you give an example of what you're trying to do?
>
> In general, it's almost always more efficient to use SQL rather than VBA
> if
> it's possible to do the same thing either way.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Bre-x" <cholotron[ at ]hotmail.com> wrote in message
> news:u6aTja%23uGHA.1504[ at ]TK2MSFTNGP03.phx.gbl...
>> Is there a way to use VBA to trim and entire record?
>>
>> I have a table that has 37 columns, each column need to be "trim"
>> I know that I can create a update query, but I would be really handy if
> VBA
>> can be use it.
>>
>> Regards,
>>
>> Bre-x
>>
>>
>
>


Re: Trim function
"Bre-x" <cholotron[ at ]hotmail.com> 09.08.2006 20:18:24
Hehehe, I forgot the actual TRIM!!! function

DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE BKARINV SET BKARINV.CUSCOD =
Trim([BKARINV]![CUSCOD]), BKARINV.SODESC = Trim([BKARINV]!
[SODESC]);"
DoCmd.SetWarnings True

thanks again



"Bre-x" <cholotron[ at ]hotmail.com> wrote in message
news:QnrCg.60$365.57[ at ]edtnps89...
[Quoted Text]
>I am dowloading some records (sales orders) from a Pervasive SQL server,
>the table has the following fields
>
> SO, double
> CUSCOD, text
> SODESC, text
>
> ratter than doing a query like this:
>
> DoCmd.SetWarnings False
> DoCmd.RunSQL "UPDATE BKARINV SET BKARINV.CUSCOD = [BKARINV]![CUSCOD],
> BKARINV.SODESC = [BKARINV]![SODESC];"
> DoCmd.SetWarnings True
>
> I would like to have a vba code, the BKARINV table has 37 columns (would
> be a longggggg query)
>
> Why?? Pervasive fills in the entire field. Example:
>
> The CUSCODE 's field lenght is 15 characters, but if you enter "JOHN",
> eventhough "JOHN" has only 4 characters
> Pervasive fill the rest with something!!! The only way to clear that
> "something" is by using the Trim funcion.
>
> Thanks for your time.
>
> Regards,
>
> Bre-x
>
>
>
>
>
>
> "Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> wrote in message
> news:ukswDj%23uGHA.4752[ at ]TK2MSFTNGP02.phx.gbl...
>> Can you give an example of what you're trying to do?
>>
>> In general, it's almost always more efficient to use SQL rather than VBA
>> if
>> it's possible to do the same thing either way.
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Bre-x" <cholotron[ at ]hotmail.com> wrote in message
>> news:u6aTja%23uGHA.1504[ at ]TK2MSFTNGP03.phx.gbl...
>>> Is there a way to use VBA to trim and entire record?
>>>
>>> I have a table that has 37 columns, each column need to be "trim"
>>> I know that I can create a update query, but I would be really handy if
>> VBA
>>> can be use it.
>>>
>>> Regards,
>>>
>>> Bre-x
>>>
>>>
>>
>>
>
>


Re: Trim function
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> 09.08.2006 21:14:22
An update query is definitely the way to go.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Bre-x" <cholotron[ at ]hotmail.com> wrote in message
news:kqrCg.62$365.50[ at ]edtnps89...
[Quoted Text]
> Hehehe, I forgot the actual TRIM!!! function
>
> DoCmd.SetWarnings False
> DoCmd.RunSQL "UPDATE BKARINV SET BKARINV.CUSCOD =
> Trim([BKARINV]![CUSCOD]), BKARINV.SODESC = Trim([BKARINV]! [SODESC]);"
> DoCmd.SetWarnings True
>
> thanks again
>
>
>
> "Bre-x" <cholotron[ at ]hotmail.com> wrote in message
> news:QnrCg.60$365.57[ at ]edtnps89...
>>I am dowloading some records (sales orders) from a Pervasive SQL server,
>>the table has the following fields
>>
>> SO, double
>> CUSCOD, text
>> SODESC, text
>>
>> ratter than doing a query like this:
>>
>> DoCmd.SetWarnings False
>> DoCmd.RunSQL "UPDATE BKARINV SET BKARINV.CUSCOD = [BKARINV]![CUSCOD],
>> BKARINV.SODESC = [BKARINV]![SODESC];"
>> DoCmd.SetWarnings True
>>
>> I would like to have a vba code, the BKARINV table has 37 columns (would
>> be a longggggg query)
>>
>> Why?? Pervasive fills in the entire field. Example:
>>
>> The CUSCODE 's field lenght is 15 characters, but if you enter "JOHN",
>> eventhough "JOHN" has only 4 characters
>> Pervasive fill the rest with something!!! The only way to clear that
>> "something" is by using the Trim funcion.
>>
>> Thanks for your time.
>>
>> Regards,
>>
>> Bre-x
>>
>>
>>
>>
>>
>>
>> "Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> wrote in message
>> news:ukswDj%23uGHA.4752[ at ]TK2MSFTNGP02.phx.gbl...
>>> Can you give an example of what you're trying to do?
>>>
>>> In general, it's almost always more efficient to use SQL rather than VBA
>>> if
>>> it's possible to do the same thing either way.
>>>
>>> --
>>> Doug Steele, Microsoft Access MVP
>>> http://I.Am/DougSteele
>>> (no e-mails, please!)
>>>
>>>
>>> "Bre-x" <cholotron[ at ]hotmail.com> wrote in message
>>> news:u6aTja%23uGHA.1504[ at ]TK2MSFTNGP03.phx.gbl...
>>>> Is there a way to use VBA to trim and entire record?
>>>>
>>>> I have a table that has 37 columns, each column need to be "trim"
>>>> I know that I can create a update query, but I would be really handy if
>>> VBA
>>>> can be use it.
>>>>
>>>> Regards,
>>>>
>>>> Bre-x
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Re: Trim function
"Albert D. Kallal" <PleaseNOOOsPAMmkallal[ at ]msn.com> 10.08.2006 04:08:55
Actually, this is a case where I would use/find code a good bit easier to
write....

Are you sure all collums need a trim?

the following code snip would do the trick...

Sub mytrimall()

Dim rst As DAO.Recordset
Dim f As DAO.Field

Set rst = CurrentDb.OpenRecordset("tblanswers")

Do While rst.EOF = False

rst.Edit
For Each f In rst.Fields

If f.Type = dbText Then
f = Trim(f)
End If
Next f
rst.Update
rst.MoveNext
Loop

rst.Close


End Sub

Note how the above code does skip non txt fields, as your table might have
id/automnumber field...



"Bre-x" <cholotron[ at ]hotmail.com> wrote in message
news:u6aTja%23uGHA.1504[ at ]TK2MSFTNGP03.phx.gbl...
[Quoted Text]
> Is there a way to use VBA to trim and entire record?
>
> I have a table that has 37 columns, each column need to be "trim"
> I know that I can create a update query, but I would be really handy if
> VBA can be use it.
>
> Regards,
>
> Bre-x
>
>


Re: Trim function
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> 10.08.2006 11:37:59
It may be easier to write, Albert, but an Update query will likely be
considerably faster.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Albert D. Kallal" <PleaseNOOOsPAMmkallal[ at ]msn.com> wrote in message
news:%23eNS0KDvGHA.2036[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
> Actually, this is a case where I would use/find code a good bit easier to
> write....
>
> Are you sure all collums need a trim?
>
> the following code snip would do the trick...
>
> Sub mytrimall()
>
> Dim rst As DAO.Recordset
> Dim f As DAO.Field
>
> Set rst = CurrentDb.OpenRecordset("tblanswers")
>
> Do While rst.EOF = False
>
> rst.Edit
> For Each f In rst.Fields
>
> If f.Type = dbText Then
> f = Trim(f)
> End If
> Next f
> rst.Update
> rst.MoveNext
> Loop
>
> rst.Close
>
>
> End Sub
>
> Note how the above code does skip non txt fields, as your table might have
> id/automnumber field...
>
>
>
> "Bre-x" <cholotron[ at ]hotmail.com> wrote in message
> news:u6aTja%23uGHA.1504[ at ]TK2MSFTNGP03.phx.gbl...
> > Is there a way to use VBA to trim and entire record?
> >
> > I have a table that has 37 columns, each column need to be "trim"
> > I know that I can create a update query, but I would be really handy if
> > VBA can be use it.
> >
> > Regards,
> >
> > Bre-x
> >
> >
>
>


Re: Trim function
"Terry Kreft" <terry.kreft[ at ]mps.co.uk> 11.08.2006 10:10:23
But you can combine the two, something like:-

Sub mytrimall()
Dim db as DAO.Database
Dim rst As DAO.Recordset
Dim f As DAO.Field
dim strSQL1 as string
dim strSQL2 as string

Const SQL_BASE = "UPDATE tblanswers SET "
Set db = Currentdb
Set rst = db.OpenRecordset("SELECT * tblanswers WHERE 1=0")

For Each f In rst.Fields
If f.Type = dbText Then
strSQL = strSQl & "[" & f.Name & "] = Trim([" & f.Name & "]), "
End If
Next

rst.Close
Set rst = Nothing

If Len(strSQL) > 0 then
strSQl = SQL_BASE & Left(strSQl, Len(strSQl) - 2)
db.Execute strSQL
End if
Set db = Nothing
End Sub


--

Terry Kreft


"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> wrote in message
news:e0WgvFHvGHA.1372[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
> It may be easier to write, Albert, but an Update query will likely be
> considerably faster.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Albert D. Kallal" <PleaseNOOOsPAMmkallal[ at ]msn.com> wrote in message
> news:%23eNS0KDvGHA.2036[ at ]TK2MSFTNGP05.phx.gbl...
> > Actually, this is a case where I would use/find code a good bit easier
to
> > write....
> >
> > Are you sure all collums need a trim?
> >
> > the following code snip would do the trick...
> >
> > Sub mytrimall()
> >
> > Dim rst As DAO.Recordset
> > Dim f As DAO.Field
> >
> > Set rst = CurrentDb.OpenRecordset("tblanswers")
> >
> > Do While rst.EOF = False
> >
> > rst.Edit
> > For Each f In rst.Fields
> >
> > If f.Type = dbText Then
> > f = Trim(f)
> > End If
> > Next f
> > rst.Update
> > rst.MoveNext
> > Loop
> >
> > rst.Close
> >
> >
> > End Sub
> >
> > Note how the above code does skip non txt fields, as your table might
have
> > id/automnumber field...
> >
> >
> >
> > "Bre-x" <cholotron[ at ]hotmail.com> wrote in message
> > news:u6aTja%23uGHA.1504[ at ]TK2MSFTNGP03.phx.gbl...
> > > Is there a way to use VBA to trim and entire record?
> > >
> > > I have a table that has 37 columns, each column need to be "trim"
> > > I know that I can create a update query, but I would be really handy
if
> > > VBA can be use it.
> > >
> > > Regards,
> > >
> > > Bre-x
> > >
> > >
> >
> >
>
>


Re: Trim function
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> 11.08.2006 21:29:56
Absolutely (other than the fact that it should be "SELECT * FROM tblanswers
WHERE 1=0" <g>)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Terry Kreft" <terry.kreft[ at ]mps.co.uk> wrote in message
news:ON2zg5SvGHA.5088[ at ]TK2MSFTNGP06.phx.gbl...
[Quoted Text]
> But you can combine the two, something like:-
>
> Sub mytrimall()
> Dim db as DAO.Database
> Dim rst As DAO.Recordset
> Dim f As DAO.Field
> dim strSQL1 as string
> dim strSQL2 as string
>
> Const SQL_BASE = "UPDATE tblanswers SET "
> Set db = Currentdb
> Set rst = db.OpenRecordset("SELECT * tblanswers WHERE 1=0")
>
> For Each f In rst.Fields
> If f.Type = dbText Then
> strSQL = strSQl & "[" & f.Name & "] = Trim([" & f.Name & "]), "
> End If
> Next
>
> rst.Close
> Set rst = Nothing
>
> If Len(strSQL) > 0 then
> strSQl = SQL_BASE & Left(strSQl, Len(strSQl) - 2)
> db.Execute strSQL
> End if
> Set db = Nothing
> End Sub
>
>
> --
>
> Terry Kreft
>
>
> "Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> wrote in message
> news:e0WgvFHvGHA.1372[ at ]TK2MSFTNGP04.phx.gbl...
>> It may be easier to write, Albert, but an Update query will likely be
>> considerably faster.
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Albert D. Kallal" <PleaseNOOOsPAMmkallal[ at ]msn.com> wrote in message
>> news:%23eNS0KDvGHA.2036[ at ]TK2MSFTNGP05.phx.gbl...
>> > Actually, this is a case where I would use/find code a good bit easier
> to
>> > write....
>> >
>> > Are you sure all collums need a trim?
>> >
>> > the following code snip would do the trick...
>> >
>> > Sub mytrimall()
>> >
>> > Dim rst As DAO.Recordset
>> > Dim f As DAO.Field
>> >
>> > Set rst = CurrentDb.OpenRecordset("tblanswers")
>> >
>> > Do While rst.EOF = False
>> >
>> > rst.Edit
>> > For Each f In rst.Fields
>> >
>> > If f.Type = dbText Then
>> > f = Trim(f)
>> > End If
>> > Next f
>> > rst.Update
>> > rst.MoveNext
>> > Loop
>> >
>> > rst.Close
>> >
>> >
>> > End Sub
>> >
>> > Note how the above code does skip non txt fields, as your table might
> have
>> > id/automnumber field...
>> >
>> >
>> >
>> > "Bre-x" <cholotron[ at ]hotmail.com> wrote in message
>> > news:u6aTja%23uGHA.1504[ at ]TK2MSFTNGP03.phx.gbl...
>> > > Is there a way to use VBA to trim and entire record?
>> > >
>> > > I have a table that has 37 columns, each column need to be "trim"
>> > > I know that I can create a update query, but I would be really handy
> if
>> > > VBA can be use it.
>> > >
>> > > Regards,
>> > >
>> > > Bre-x
>> > >
>> > >
>> >
>> >
>>
>>
>
>


Re: Trim function
"Terry Kreft" <terry.kreft[ at ]mps.co.uk> 12.08.2006 18:06:22
Ahh, you spotted the (not so) deliberate mistake <g>.


--

Terry Kreft


"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> wrote in message
news:%23eq2L1YvGHA.5044[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text]
> Absolutely (other than the fact that it should be "SELECT * FROM
tblanswers
> WHERE 1=0" <g>)
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "Terry Kreft" <terry.kreft[ at ]mps.co.uk> wrote in message
> news:ON2zg5SvGHA.5088[ at ]TK2MSFTNGP06.phx.gbl...
> > But you can combine the two, something like:-
> >
> > Sub mytrimall()
> > Dim db as DAO.Database
> > Dim rst As DAO.Recordset
> > Dim f As DAO.Field
> > dim strSQL1 as string
> > dim strSQL2 as string
> >
> > Const SQL_BASE = "UPDATE tblanswers SET "
> > Set db = Currentdb
> > Set rst = db.OpenRecordset("SELECT * tblanswers WHERE 1=0")
> >
> > For Each f In rst.Fields
> > If f.Type = dbText Then
> > strSQL = strSQl & "[" & f.Name & "] = Trim([" & f.Name & "]), "
> > End If
> > Next
> >
> > rst.Close
> > Set rst = Nothing
> >
> > If Len(strSQL) > 0 then
> > strSQl = SQL_BASE & Left(strSQl, Len(strSQl) - 2)
> > db.Execute strSQL
> > End if
> > Set db = Nothing
> > End Sub
> >
> >
> > --
> >
> > Terry Kreft
> >
> >
> > "Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> wrote in message
> > news:e0WgvFHvGHA.1372[ at ]TK2MSFTNGP04.phx.gbl...
> >> It may be easier to write, Albert, but an Update query will likely be
> >> considerably faster.
> >>
> >> --
> >> Doug Steele, Microsoft Access MVP
> >> http://I.Am/DougSteele
> >> (no e-mails, please!)
> >>
> >>
> >> "Albert D. Kallal" <PleaseNOOOsPAMmkallal[ at ]msn.com> wrote in message
> >> news:%23eNS0KDvGHA.2036[ at ]TK2MSFTNGP05.phx.gbl...
> >> > Actually, this is a case where I would use/find code a good bit
easier
> > to
> >> > write....
> >> >
> >> > Are you sure all collums need a trim?
> >> >
> >> > the following code snip would do the trick...
> >> >
> >> > Sub mytrimall()
> >> >
> >> > Dim rst As DAO.Recordset
> >> > Dim f As DAO.Field
> >> >
> >> > Set rst = CurrentDb.OpenRecordset("tblanswers")
> >> >
> >> > Do While rst.EOF = False
> >> >
> >> > rst.Edit
> >> > For Each f In rst.Fields
> >> >
> >> > If f.Type = dbText Then
> >> > f = Trim(f)
> >> > End If
> >> > Next f
> >> > rst.Update
> >> > rst.MoveNext
> >> > Loop
> >> >
> >> > rst.Close
> >> >
> >> >
> >> > End Sub
> >> >
> >> > Note how the above code does skip non txt fields, as your table might
> > have
> >> > id/automnumber field...
> >> >
> >> >
> >> >
> >> > "Bre-x" <cholotron[ at ]hotmail.com> wrote in message
> >> > news:u6aTja%23uGHA.1504[ at ]TK2MSFTNGP03.phx.gbl...
> >> > > Is there a way to use VBA to trim and entire record?
> >> > >
> >> > > I have a table that has 37 columns, each column need to be "trim"
> >> > > I know that I can create a update query, but I would be really
handy
> > if
> >> > > VBA can be use it.
> >> > >
> >> > > Regards,
> >> > >
> >> > > Bre-x
> >> > >
> >> > >
> >> >
> >> >
> >>
> >>
> >
> >
>
>


Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net