Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » Access

Data Type problem

 
Jump to:  
 
magmike
PostPosted: Wed Sep 03, 2008 3:26 am    Post subject: Data Type problem
       
First thing - I did not create this database! I was however, asked by
my boss to add a search form to it. Here are the details.

The key field is the social security number field. It is set as text.
I am having conflict issues when searching. When the button code below
is run, I get a Data Type error.

There are two forms, [Form1 - MAIN], and [Search]. Search is a
continuous form. From the Search form, a user can select the Go!
button next to a record and it is supposed to find the record in the
first form. Here is the code:

Private Sub Command63_Click()
On Error GoTo Err_Command63_Click

Dim rs As Object
Dim stDocName As String

stDocName = "Form1 - MAIN"
DoCmd.OpenForm stDocName

Set rs = Forms![Form1 - MAIN].Recordset.Clone
rs.FindFirst "[SSNo] = " & Str(Nz(Me![SSNo], 0))
If Not rs.EOF Then Forms![Form1 - MAIN].Bookmark = rs.Bookmark

Forms!search.Visible = False

Exit_Command63_Click:
Exit Sub

Err_Command63_Click:
MsgBox Err.Description
Resume Exit_Command63_Click
End Sub

If I change SSNo to a number field, the above code works fine, however
the social security number "003-55-5555" ends up being stored and
displayed as "3-55-5555" which of course is not cool. Is there a way
to change the above code to represent the results as text, or is there
a way to make the SSNo a number, but display and store properly when
the number begins with a zero?

PS: SSNo stores the data without the mask, in case that is important.

Thanks in advance for your help!
 

 
pietlinden@hotmail.com
PostPosted: Wed Sep 03, 2008 3:31 am    Post subject: Re: Data Type problem
       
On Sep 2, 10:26 pm, magmike <magmi...@yahoo.com> wrote:
Quote:
First thing - I did not create this database! I was however, asked by
my boss to add a search form to it. Here are the details.

The key field is the social security number field. It is set as text.
I am having conflict issues when searching. When the button code below
is run, I get a Data Type error.

There are two forms, [Form1 - MAIN], and [Search]. Search is a
continuous form. From the Search form, a user can select the Go!
button next to a record and it is supposed to find the record in the
first form. Here is the code:


   
    rs.FindFirst "[SSNo] = " & Str(Nz(Me![SSNo], 0))

should be rs.FindFirst "[SSNo] = ' " & Me![SSNo] & " ' "

(but without the extra spaces around the single quotes.)
 

 
fredg
PostPosted: Wed Sep 03, 2008 3:50 am    Post subject: Re: Data Type problem
       
On Tue, 2 Sep 2008 20:26:17 -0700 (PDT), magmike wrote:

Quote:
First thing - I did not create this database! I was however, asked by
my boss to add a search form to it. Here are the details.

The key field is the social security number field. It is set as text.
I am having conflict issues when searching. When the button code below
is run, I get a Data Type error.

There are two forms, [Form1 - MAIN], and [Search]. Search is a
continuous form. From the Search form, a user can select the Go!
button next to a record and it is supposed to find the record in the
first form. Here is the code:

Private Sub Command63_Click()
On Error GoTo Err_Command63_Click

Dim rs As Object
Dim stDocName As String

stDocName = "Form1 - MAIN"
DoCmd.OpenForm stDocName

Set rs = Forms![Form1 - MAIN].Recordset.Clone
rs.FindFirst "[SSNo] = " & Str(Nz(Me![SSNo], 0))
If Not rs.EOF Then Forms![Form1 - MAIN].Bookmark = rs.Bookmark

Forms!search.Visible = False

Exit_Command63_Click:
Exit Sub

Err_Command63_Click:
MsgBox Err.Description
Resume Exit_Command63_Click
End Sub

If I change SSNo to a number field, the above code works fine, however
the social security number "003-55-5555" ends up being stored and
displayed as "3-55-5555" which of course is not cool. Is there a way
to change the above code to represent the results as text, or is there
a way to make the SSNo a number, but display and store properly when
the number begins with a zero?

PS: SSNo stores the data without the mask, in case that is important.

Thanks in advance for your help!

You a misstatement of fact here.
1) A Number datatype field cannot store a number with the hyphens as
you show them. 003-55-5555 cannot be a number datatype (even though
numbers make up the data.) What you are seeing is most probably the
effects of an input mask on the data, while the actual stored value
(as a number datatype) is 3555555.

2) The SSN field should be a Text datatype, in which case you must
surround the text value with single quotes.
Try:
rs.FindFirst "[SSNo] = '" & Str(Nz(Me![SSNo], 0) & "'"

which will evaluate to
rs.FindFirst "[SSNo] = '003-55-5555'"

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 

 
magmike
PostPosted: Wed Sep 03, 2008 4:31 am    Post subject: Re: Data Type problem
       
On Sep 2, 10:31 pm, "pietlin...@hotmail.com" <pietlin...@hotmail.com>
wrote:
Quote:
On Sep 2, 10:26 pm, magmike <magmi...@yahoo.com> wrote:

First thing - I did not create this database! I was however, asked by
my boss to add a search form to it. Here are the details.

The key field is the social security number field. It is set as text.
I am having conflict issues when searching. When the button code below
is run, I get a Data Type error.

There are two forms, [Form1 - MAIN], and [Search]. Search is a
continuous form. From the Search form, a user can select the Go!
button next to a record and it is supposed to find the record in the
first form. Here is the code:

   
    rs.FindFirst "[SSNo] = " & Str(Nz(Me![SSNo], 0))

should be rs.FindFirst "[SSNo] = ' " & Me![SSNo] & " ' "

(but without the extra spaces around the single quotes.)

That was easy!
(am I at Staples?)
 

 
pietlinden@hotmail.com
PostPosted: Wed Sep 03, 2008 4:40 am    Post subject: Re: Data Type problem
       
On Sep 2, 11:31 pm, magmike <magmi...@yahoo.com> wrote:
Quote:
On Sep 2, 10:31 pm, "pietlin...@hotmail.com" <pietlin...@hotmail.com
wrote:



On Sep 2, 10:26 pm, magmike <magmi...@yahoo.com> wrote:

First thing - I did not create this database! I was however, asked by
my boss to add a search form to it. Here are the details.

The key field is the social security number field. It is set as text.
I am having conflict issues when searching. When the button code below
is run, I get a Data Type error.

There are two forms, [Form1 - MAIN], and [Search]. Search is a
continuous form. From the Search form, a user can select the Go!
button next to a record and it is supposed to find the record in the
first form. Here is the code:

   
    rs.FindFirst "[SSNo] = " & Str(Nz(Me![SSNo], 0))

should be rs.FindFirst "[SSNo] = ' " & Me![SSNo] & " ' "

(but without the extra spaces around the single quotes.)

That was easy!
(am I at Staples?)

not sure... did you see the big red button?
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

Kredyty mieszkaniowe santander consumer bank ubranka dla dzieci Pozycjonowanie certyfikat mobing