943,704 Members | Top Members by Rank

Ad:
Jun 15th, 2009
0

Run time error 13 - type mismatch

Expand Post »
Hi,
Im new to VB. Im just trying to do a simple if statement that will open a specific form based on user input. The database requires me to scan in a barcode from a card. I then want to check if that barcode number is already in the database. to do this i have tried the following code.

Vb Syntax (Toggle Plain Text)
  1. Private Sub Barcode_AfterUpdate()
  2. Dim curDatabase As Object
  3. Dim tblStore_Barcode As Object
  4. Dim tblPersonal As Object
  5.  
  6.  
  7. Set curDatabase = CurrentDb
  8. Set tblStore_Barcode = curDatabase.TableDefs("Store_Barcode")
  9. Set tblPersonal = curDatabase.TableDefs("Personal")
  10.  
  11.  
  12. If [Store_Barcode]![Barcode] = [Personal]![Barcode] Then
  13. DoCmd.OpenForm (Personal_2)
  14. Else
  15. DoCmd.OpenForm (Personal)
  16. End If
  17. End Sub

I recieve the Run time error 13 - type mismatch
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If [Store_Barcode]![Barcode] = [Personal]![Barcode] Then
This is the line that is highlighted. Any ideas why it is doing this?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Cosa is offline Offline
63 posts
since Mar 2008
Jun 15th, 2009
0

Re: Run time error 13 - type mismatch

Please check the data type of the fields 'Barcode' in both table, the Personal and the Store_Barcode. The data type of the two must be the same, example the Barcode in Personal is in Integer data type and the other is in "Text/Char" data type, then it would really return an Error.
Reputation Points: 6
Solved Threads: 5
Light Poster
Cruize_Invades is offline Offline
40 posts
since May 2007
Jun 15th, 2009
0

Re: Run time error 13 - type mismatch

The datatype is the same for both. I made sure of that before i attempted writing the code, and i have since checked it several times to be sure.

I believe the problem is with the actual syntax. However i dont know why it is doing this.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Cosa is offline Offline
63 posts
since Mar 2008
Jun 15th, 2009
0

Re: Run time error 13 - type mismatch

Any ideas guys?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Cosa is offline Offline
63 posts
since Mar 2008
Jun 16th, 2009
0

Re: Run time error 13 - type mismatch

Unless the two tables are exact (TableDefs) then they... Is this VBA?
Reputation Points: 156
Solved Threads: 296
Posting Virtuoso
vb5prgrmr is offline Offline
1,670 posts
since Mar 2009
Jun 17th, 2009
0

Re: Run time error 13 - type mismatch

try to remove the bracket "[]"

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If [Store_Barcode]![Barcode] = [Personal]![Barcode] Then

or try to look the value if it is DBNull. dbnull is not a string type in which if you will try to use it in comparison of strings it would throw an exception error...
Last edited by jireh; Jun 17th, 2009 at 11:12 am.
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: pls help me how to disable Ctrl + Esc key vb6
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB6 and Excel





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC