Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Access (https://www.askmehelpdesk.com/forumdisplay.php?f=441)
-   -   Could someone help me out with VB code? (https://www.askmehelpdesk.com/showthread.php?t=805394)

  • Dec 2, 2014, 08:05 PM
    lisabaker
    Could someone help me out with VB code?
    Hi,

    I have a problem with my VB code in Access saying 'Run-time error 3075': Syntax Error in query expression '[Survey Questions].*'

    The code is as follows:

    Private Sub Report_Open(Cancel As Integer)

    'Declare Variables
    Dim strR5 As String
    Dim intSeminar As Integer

    'Get the seminar from the Select Seminar form
    intSeminar = Forms![Select Seminar]![cboSelectSeminar]

    'Set the record source
    strR5 = "SELECT [Survey Questions]. * FROM [Survey Questions] WHERE SeminarID =" & intSeminar <------- highlighted
    Me.RecordSource = strR5

    End Sub

    Could someone help me out? My textbook is of no help.

    Thanks in advance!
    Lisa
  • Jan 28, 2015, 04:33 PM
    GaryStaunton
    Hi "SELECT [Survey Questions]. * FROM [Survey Questions] WHERE SeminarID =" & intSeminar Why do you have a full-stop here "[Survey Questions]."? I'm guessing this is the problem.
  • Jan 28, 2015, 05:08 PM
    ScottGem
    Lisa,

    This is VBA code, not VB code. There is a difference. VBA is a superset of VB with extensions specific to the application the code is run from. So your question has been moved to the Access forum.

    The line of code should look like this:

    strR5 = "SELECT [Survey Questions].* FROM [Survey Questions] WHERE SeminarID =" & intSeminar & ";"

    You had a space before the * and no semi colon after concatenating in intSeminar.

    You could shorten the code, since you don't need the intSeminar, you could just use:

    strR5 = "SELECT [Survey Questions].* FROM [Survey Questions] WHERE SeminarID =" & Forms![Select Seminar]![cboSelectSeminar] & ";"

    Frankly, however I wouldn't do it this way. Instead I would do it like this:

    Me.Filter = "[SeminarID] = " & Forms![Select Seminar]![cboSelectSeminar]
    DoCmd.RunCommand acCmdApplyFilterSort

    This allows you to just filter the form by the selected seminar rather then replace the Recordsource.

  • All times are GMT -7. The time now is 07:57 AM.