Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Posts
    73

    Unanswered: Getting with error with my DB

    I've been stumped on this for the past few hours.

    I'm trying to get my sub forms to open a new main form.

    The code I have for my button to do so is the following:
    --------------------------------------------------------------------------
    Private Sub Command21a_Click()

    On Error GoTo Err_Command21a_Click
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Refresh
    If IsNull(Me![CompanyCode]) Then
    MsgBox ("You cannot open this trade show form because it does not exist. You must enter form information before it can be opened.")
    Me![CompanyCode].SetFocus
    Exit Sub
    End If
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Trade Show Form"

    stLinkCriteria = "[CompanyCode]=" & Me![CompanyCode]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Command21a_Click:
    Exit Sub

    Err_Command21a_Click:
    MsgBox Err.Description
    Resume Exit_Command21a_Click

    End Sub
    --------------------------------------------------------------------------
    When I have a value in my CompanyCode area, it prompts me for a paramater value.

    But when on the odd one, I get a Syntax error (missing operator) in query expression '[CompanyCode] = '.

    Now..I've used the above code on all my other commands to open a new form when clicked and have not recieved this error on any of the others. Any idea on what could be causing this??

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Welcome:

    Well.....I supose it really all depends upon whether or not the Data Type for [CompanyCode] is Text or Number. If your is string then criteria should be:

    stLinkCriteria = "[CompanyCode]='" & Me.CompanyCode & "'"


    If not, then try...

    stLinkCriteria = "[CompanyCode]=" & CLng(Me.CompanyCode)

    Curious...is the button actually in your SubForm?
    Last edited by CyberLynx; 03-13-06 at 22:42.
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  3. #3
    Join Date
    Mar 2006
    Posts
    73
    Thank you! heh...the first line there worked for me..

    and ya the button is located right in the subform itself.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •