PC Review


Reply
Thread Tools Rate Thread

Confusing Type Mismatch

 
 
thefonz37
Guest
Posts: n/a
 
      3rd Nov 2008
Let me preface by saying that in my database, I am storing employee
information inside of two tables - one for general information (Employee ID
#, name, hire date, supervisor name, etc), and one for login information into
our various business applications. These tables are joined on Employee ID
fields, which are text values in both tables.

I'm trying to design a form where users can edit employee data, but the
problem is that if somebody modifies an employee ID, it no longer associates
the employee properly with their logins, as this is the key that joins the
two. So I tried to write some code related to the Employee ID box on the
form to update the login table with the new data:

Dim oldEmpID As String

Private Sub EmpID_AfterUpdate()
Dim sqlQry As String
sqlQry = "UPDATE [Logins_Data] SET [Logins_Data].EmpID = [Forms]![Edit
Employee Data]![EmpID] WHERE [Logins_Data].EmpID=" & oldEmpID & ";"
DoCmd.RunSQL sqlQry

If Me.Dirty Then
Me.Dirty = False
End If
End Sub

Private Sub EmpID_Change()
oldEmpID = [Forms]![Edit Employee Data]![EmpID]
End Sub


Everything works ok if I replace "oldEmpID" with any other value in the SQL
Update statement, but if I leave it as it is above, I get a type mismatch. I
don't get it because oldEmpID and the EmpID field of the login table is text.
 
Reply With Quote
 
 
 
 
Pendragon
Guest
Posts: n/a
 
      3rd Nov 2008
Because you have used EmpID as a text field, you need to have single quotes
before and after oldEmpID in your WHERE clause.

WHERE [Logins_Data].EmpID= '" & oldEmpID & "';"

note that there is a single quote before the first quotation mark and a
single quote after the second quotation mark and before the semicolon.

Since you are utilizing a form for users to update information, you can
always lock the EmpID field so it can't be edited.

If your EmpID is not alphanumeric, how about just using an autonumber field
as a primary key for EmpID?

"thefonz37" wrote:

> Let me preface by saying that in my database, I am storing employee
> information inside of two tables - one for general information (Employee ID
> #, name, hire date, supervisor name, etc), and one for login information into
> our various business applications. These tables are joined on Employee ID
> fields, which are text values in both tables.
>
> I'm trying to design a form where users can edit employee data, but the
> problem is that if somebody modifies an employee ID, it no longer associates
> the employee properly with their logins, as this is the key that joins the
> two. So I tried to write some code related to the Employee ID box on the
> form to update the login table with the new data:
>
> Dim oldEmpID As String
>
> Private Sub EmpID_AfterUpdate()
> Dim sqlQry As String
> sqlQry = "UPDATE [Logins_Data] SET [Logins_Data].EmpID = [Forms]![Edit
> Employee Data]![EmpID] WHERE [Logins_Data].EmpID=" & oldEmpID & ";"
> DoCmd.RunSQL sqlQry
>
> If Me.Dirty Then
> Me.Dirty = False
> End If
> End Sub
>
> Private Sub EmpID_Change()
> oldEmpID = [Forms]![Edit Employee Data]![EmpID]
> End Sub
>
>
> Everything works ok if I replace "oldEmpID" with any other value in the SQL
> Update statement, but if I leave it as it is above, I get a type mismatch. I
> don't get it because oldEmpID and the EmpID field of the login table is text.

 
Reply With Quote
 
thefonz37
Guest
Posts: n/a
 
      3rd Nov 2008
Perfect, thank you, that's exactly what I needed to know.

Unforunately, as much as I would like to completely hide the value or lock
it, it's actually an ID number generated by our payroll system that's
generally used for most (if not all) identification purposes throughout the
company. They are numbers, but sometimes contain a leading zero, which is
not preserved in Access, but can be important for other things. I also
wanted to make it available for editing in the event that someone enters the
employee ID wrong, so that it can later be fixed.

Thanks so much for the help, though.

"Pendragon" wrote:

> Because you have used EmpID as a text field, you need to have single quotes
> before and after oldEmpID in your WHERE clause.
>
> WHERE [Logins_Data].EmpID= '" & oldEmpID & "';"
>
> note that there is a single quote before the first quotation mark and a
> single quote after the second quotation mark and before the semicolon.
>
> Since you are utilizing a form for users to update information, you can
> always lock the EmpID field so it can't be edited.
>
> If your EmpID is not alphanumeric, how about just using an autonumber field
> as a primary key for EmpID?
>
> "thefonz37" wrote:
>
> > Let me preface by saying that in my database, I am storing employee
> > information inside of two tables - one for general information (Employee ID
> > #, name, hire date, supervisor name, etc), and one for login information into
> > our various business applications. These tables are joined on Employee ID
> > fields, which are text values in both tables.
> >
> > I'm trying to design a form where users can edit employee data, but the
> > problem is that if somebody modifies an employee ID, it no longer associates
> > the employee properly with their logins, as this is the key that joins the
> > two. So I tried to write some code related to the Employee ID box on the
> > form to update the login table with the new data:
> >
> > Dim oldEmpID As String
> >
> > Private Sub EmpID_AfterUpdate()
> > Dim sqlQry As String
> > sqlQry = "UPDATE [Logins_Data] SET [Logins_Data].EmpID = [Forms]![Edit
> > Employee Data]![EmpID] WHERE [Logins_Data].EmpID=" & oldEmpID & ";"
> > DoCmd.RunSQL sqlQry
> >
> > If Me.Dirty Then
> > Me.Dirty = False
> > End If
> > End Sub
> >
> > Private Sub EmpID_Change()
> > oldEmpID = [Forms]![Edit Employee Data]![EmpID]
> > End Sub
> >
> >
> > Everything works ok if I replace "oldEmpID" with any other value in the SQL
> > Update statement, but if I leave it as it is above, I get a type mismatch. I
> > don't get it because oldEmpID and the EmpID field of the login table is text.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type mismatch: array or user-defined type expected Naftas Microsoft Excel Programming 3 23rd Mar 2010 03:43 PM
Type Mismatch: array or user defined type expected =?Utf-8?B?RXhjZWxNb25rZXk=?= Microsoft Excel Programming 4 6th Jul 2006 03:40 PM
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Microsoft Excel Programming 11 3rd Dec 2005 05:02 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Microsoft Excel Programming 1 31st Oct 2005 08:20 PM
Type mismatch error (different than previous type mismatch?) Roberta Microsoft Access VBA Modules 3 9th Jan 2004 06:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:15 AM.