PDA

View Full Version : Could someone help me out with VB code?


lisabaker
Dec 2, 2014, 08:05 PM
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

GaryStaunton
Jan 28, 2015, 04:33 PM
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.

ScottGem
Jan 28, 2015, 05:08 PM
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.