Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB Script in Access

Posted on 2012-03-15
4
Medium Priority
?
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 34

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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

719 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