CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2006
    Posts
    12

    Exclamation problem in formula

    Dear All,

    i am using cr 8.5, vb6 & MS Access 2007.
    My problem is that when i am trying to fetch data from access with the help of formula i receive this error:

    A number, currency amount, boolean, date, time, date-time, or string is expected here.

    this is my code as mentioned below:

    Me.MousePointer = vbHourglass
    If Combo1.Text = "" Then
    Inventrymain.cr1.ReportFileName = App.Path + "\chartofaccounts.rpt"
    Inventrymain.cr1.Connect = ";Pwd=" & "system"
    Inventrymain.cr1.RetrieveDataFiles
    Inventrymain.cr1.DiscardSavedData = True
    Inventrymain.cr1.ReportSource = 0
    Inventrymain.cr1.WindowTitle = " Chart of Items "
    strformula = "{subcodes.accode}<> 0 "
    Inventrymain.cr1.ReplaceSelectionFormula (strformula)
    Inventrymain.cr1.WindowState = crptMaximized
    Unload Me
    On Error Resume Next
    Inventrymain.cr1.Action = 1
    Else
    Inventrymain.cr1.ReportFileName = App.Path + "\chartofaccounts.rpt"
    Inventrymain.cr1.Connect = ";Pwd=" & "system"
    Inventrymain.cr1.RetrieveDataFiles
    Inventrymain.cr1.DiscardSavedData = True
    Inventrymain.cr1.ReportSource = 0
    Inventrymain.cr1.WindowTitle = " Chart of Items "


    strformula = "{subcodes.accode} = " & Combo2.Text & ""

    Inventrymain.cr1.ReplaceSelectionFormula (strformula)
    Inventrymain.cr1.WindowState = crptMaximized
    Unload Me
    On Error Resume Next
    Inventrymain.cr1.Action = 1
    End If

    Private Sub Form_Load()
    con
    Set rs = cn.Execute("select Distinct accode,acname from subcodes order by accode")
    Do While Not rs.EOF
    Combo1.AddItem rs(0) & " - " & rs(1)
    Combo2.AddItem rs(0)
    rs.MoveNext
    Loop
    End Sub

    in access database accode & acname all are text string.

    please help me about this issue.

    thnx in advance

  2. #2
    Join Date
    Jul 2005
    Posts
    1,083

    Re: problem in formula

    If the field is strig type then enclose the constant between ' , as in the next example
    Code:
    strformula = "{subcodes.accode} <> '0'"
    ...
    ...
    strformula = "{subcodes.accode} = " & Chr(39) & Combo2.Text & chr(39)
    JG
    Last edited by jggtz; January 19th, 2011 at 05:26 PM.

  3. #3
    Join Date
    Sep 2006
    Posts
    12

    Thumbs up Re: problem in formula

    thnx jggtz. it's working

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured