I have a database I've been designing to track projects. I'm having trouble setting up a DoCmd to open a form to specific records where field values contain alphanumerics. I'll try to keep this simple.
I think this is a datatype mismatch issue. Any ideas how to setup a DoCmd to open a form to a record where the value in a field in a table is alphanumeric and matches the value a user types into a text box? Can anybody spot what I'm doing wrong? It works perfect with numbers, but not strings.
Some details are:
tblProjects
-Contains a field called ProjectNumber, which is not a primary key
-Project numbers are not determined by me, but are assigned based on the department I am working with
-These project numbers are Alphanumeric and therefore I set the data type for this field to be Long Text
frmProject
-This is the form tied to tblProjects where users enter project information into the fields
frmHome
-This is essentially the home screen, opens upon opening database
-This form has a text box called txtProjectNumber
-This form also has a command button called cmdProjectNumber
-User types the project number into txtProjectNumber and it is intended to open frmProject to a record were the field ProjectNumber from tblProjects matches the value in txtProjectNumber
When I try to do the same thing with other fields in the same table where the datatype is Number, the following code works PERFECT. The command button opens frmProject to records where value in a field in tblProjects is equal to the value held in the text box where the user is typing the value in to search. For example, with quote numbers, because they are a number datatype, this works perfect.
DoCmd.OpenForm "frmProject", acNormal, "", "[Quote Number] =" & [Forms]![frmHome]![txtQuote], acEdit, acNormal
When I try the same thing with a Long Text field, the DoCmd cannot find a matching record, I suspect because of a mismatch in datatypes. So, I tried converting both the value in the field and the value being searched into strings. This works beautifully only if values in Project Number field are numbers (even though data type is set to long text).
DoCmd.OpenForm "frmProject", acNormal, "", "Str([Project Number]) =" & Str([Forms]![frmHome]![txtProjectNumber]), acEdit, acNormal
For example, project number 123 is held in the field Project Number. User types 123 into the text box and searches, frmProject opens perfectly to this record.
If i change 123 to 123ABC in the table, and the user searches 123ABC, no records are found. In fact, i now find that as soon as a single alphanumeric value appears in any cell of this field in this table, the DoCmd cannot find ANY records, even ones that only have numbers in other cells of this field.
I think this is a datatype mismatch issue. Any ideas how to setup a DoCmd to open a form to a record where the value in a field in a table is alphanumeric and matches the value a user types into a text box? Can anybody spot what I'm doing wrong? It works perfect with numbers, but not strings.
Some details are:
tblProjects
-Contains a field called ProjectNumber, which is not a primary key
-Project numbers are not determined by me, but are assigned based on the department I am working with
-These project numbers are Alphanumeric and therefore I set the data type for this field to be Long Text
frmProject
-This is the form tied to tblProjects where users enter project information into the fields
frmHome
-This is essentially the home screen, opens upon opening database
-This form has a text box called txtProjectNumber
-This form also has a command button called cmdProjectNumber
-User types the project number into txtProjectNumber and it is intended to open frmProject to a record were the field ProjectNumber from tblProjects matches the value in txtProjectNumber
When I try to do the same thing with other fields in the same table where the datatype is Number, the following code works PERFECT. The command button opens frmProject to records where value in a field in tblProjects is equal to the value held in the text box where the user is typing the value in to search. For example, with quote numbers, because they are a number datatype, this works perfect.
DoCmd.OpenForm "frmProject", acNormal, "", "[Quote Number] =" & [Forms]![frmHome]![txtQuote], acEdit, acNormal
When I try the same thing with a Long Text field, the DoCmd cannot find a matching record, I suspect because of a mismatch in datatypes. So, I tried converting both the value in the field and the value being searched into strings. This works beautifully only if values in Project Number field are numbers (even though data type is set to long text).
DoCmd.OpenForm "frmProject", acNormal, "", "Str([Project Number]) =" & Str([Forms]![frmHome]![txtProjectNumber]), acEdit, acNormal
For example, project number 123 is held in the field Project Number. User types 123 into the text box and searches, frmProject opens perfectly to this record.
If i change 123 to 123ABC in the table, and the user searches 123ABC, no records are found. In fact, i now find that as soon as a single alphanumeric value appears in any cell of this field in this table, the DoCmd cannot find ANY records, even ones that only have numbers in other cells of this field.