Solved

VB Script in Access

Posted on 2012-03-15
4
250 Views
Last Modified: 2012-03-19
I have a script I am trying to use in Access 2007. I am using it in a form to automatically insert data from a field in one form, into another form. I use a similar script in a different form without any problems. When I try to use it in this new form, I get an error when I double click the field that reads "Type Mismatch" Can someone tell me what is causing the error?
Private Sub On_Hold_DblClick(Cancel As Integer)

On Error GoTo Err_On_Hold_DblClick

    Dim stDocName As String
    Dim stLinkCriteria As Integer
    Me!LastRecordNumber = Me.CurrentRecord

    stDocName = "FrmStatus"
    
    stLinkCriteria = "([MOLineKey1]='" & Me![MOLineKey] & "')"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_On_Hold_DblClick:
    Exit Sub

Err_On_Hold_DblClick:
    MsgBox Err.Description
    Resume Exit_On_Hold_DblClick
End Sub

Open in new window

0
Comment
Question by:CJSilver
  • 2
4 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 37727231
That code only seems to open a form.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37727465
Your criteria is currently defined as integer, but you are assigning a string to it, resulting in a type mismatch.  It should be defined as string:


On Error GoTo Err_On_Hold_DblClick

    Dim stDocName As String
    Dim stLinkCriteria As String
    Me!LastRecordNumber = Me.CurrentRecord

    stDocName = "FrmStatus"
   
    stLinkCriteria = "[MOLineKey1]='" & Me![MOLineKey] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_On_Hold_DblClick:
    Exit Sub

Err_On_Hold_DblClick:
    MsgBox Err.Description
    Resume Exit_On_Hold_DblClick
End Sub
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 37727475
The above assumes that the datatype of MOLineKey1 is TEXT.  If MOLineKey1 is a text/integer field, then the criteria should still be defined as a string, but the sytax would be slightly different (no embedded quote delimiters for numeric data types):


On Error GoTo Err_On_Hold_DblClick

    Dim stDocName As String
    Dim stLinkCriteria As String
    Me!LastRecordNumber = Me.CurrentRecord

    stDocName = "FrmStatus"
   
' use this syntax for numeric MOLineKey1
    stLinkCriteria = "[MOLineKey1]=" & Me![MOLineKey]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_On_Hold_DblClick:
    Exit Sub

Err_On_Hold_DblClick:
    MsgBox Err.Description
    Resume Exit_On_Hold_DblClick
End Sub
0
 
LVL 1

Author Closing Comment

by:CJSilver
ID: 37738583
Thank you mbizup, that worked perfectly!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now