- This topic is empty.
-
AuthorPosts
-
-
November 15, 2005 at 3:01 pm #9355applejackMember
I realize that this is a SQL based group, sorry if this offends anyone.
This is my first post, and my first attempt at this type of programming.
This is from MS Access 2003. I get the following error:
Run-time error '3131':
Syntax error in FROM clause.
Below is the code for the button that I am using. Can anyone see what I
must've overlooked. Any help is appreciated!
Applejack 🙄
Private Sub Command19_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs(“qrySEEKER”)
strSQL = “SELECT tbl_MishapDatabase.*” & “FROM tbl_MishapDatabase” & “WHERE tbl_MishapDatabase.Rank='” & Me.cboRank.Value & “'” & “AND tbl_MishapDatabase.Duty='” & Me.cboDutyStatus.Value & “'” & “AND tbl_MishapDatabase.Class='” & Me.cboClass.Value & “'” & “AND tbl_MishapDatabase.Unit='” & Me.cboUnit.Value & “'” & “AND tbl_MishapDatabase.InjuryType='” & Me.cboInjuryType.Value & “'”
qdf.SQL = strSQL
DoCmd.OpenQuery “qrySEEKER”
DoCmd.Close acForm, Me.Name
Set qdf = Nothing
Set db = Nothing
End Sub
-
November 17, 2005 at 3:40 am #19749peterlaursenParticipant
there are nore problems I believe
1) the beginning of the SQL-string concatenates to
QUOTESELECT tbl_MishapDatabase.*FROM tbl_MishapDatabaseWHERE tbl_MishapDatabase.Rank=' … etcYou must put in a blank before WHERE … but that's a problem more places in the code.
But this one generates the first eror (the one that you get). There is no table 'tbl_MishapDatabaseWHERE' I guess … 😛
2) This will give you problems too:
strSQL =
= strSQL It looks lik VB to me and I don't know it very well but it should probably only be
strSQL =
3) I doubt that all the quotes are put the right places! But it is impossible to judge in this layout. Use the CODE tage of the Forums system! But in general reading VB is hopeless …
You should write a program that prints the strSQL to a file and have a look at the SQL statement generated. And verify the that SQL itself runs and retursn as expected. SQLyog is very good for this. Also writing the strSQL to a messagebox while you are developing is a simple trick if you have no other and better debugger.
You can delete or comment-out the messagebox when you have verified it.
-
-
AuthorPosts
- You must be logged in to reply to this topic.