Solved

VB Script in Access

Posted on 2012-03-15
4
251 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

785 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