Volunteer needs help with select statement

Here is what i have

Option Explicit
Function BuryPostCode()
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT First_Name, " _
& "Last_Name FROM [Members_Contact_Details];")
dbs.Close
End Function
Private Sub Command4_Click()
End Sub
 
If there are actually spaces, take out the underscores and replace them with spaces.
 
Now i get a defferent run time error as follows

Run time error 3061

too few parameters, expected 2

any ideas?
 
Do the field names have spaces too? Same fix if so.
 
The code that is not working is as follows

Set rst = dbs.OpenRecordset("SELECT First_Name, " _
& "Last_Name FROM [Members_Contact_Details];")

Its not recognizing this command and i don’t know why as the table exist and i have taken out the underscore and replaced with spaces
 
The code that is not working is as follows

Set rst = dbs.OpenRecordset("SELECT First_Name, " _
& "Last_Name FROM [Members_Contact_Details];")

Its not recognizing this command and i don’t know why as the table exist and i have taken out the underscore and replaced with spaces


The Table name must exactly match the Table name in the Access Datyabase. Your Query has underscores, but you say you have taken them out. The same rule applies to the Column names.
 
Last edited:
Try this

Set rst = dbs.OpenRecordset("SELECT [First Name], " _
& "[Last Name] FROM [Members Contact Details];")
 
Here is what i have up to know from the following posts

Function BuryPostCode()
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT [First_Name], "_
& "[Last_Name] FROM [Members_Contact_Details];")
dbs.Close
End Function
Private Sub Command4_Click()
End Sub

Is this correct with the brackets
 
Did you try what I posted?
 
Would it be possible for us to see a copy of the database (with any sensitive information replaced with dummy information of course)?
 
I am a little surprised that you have repeatedly said there were spaces in the table name, that people told you to put those spaces in the table name, and that you posted the exact same table name with the underscores.

What is the EXACT name of the table? I don't mean kind of, I mean EXACT. Just to be clear "_" is exactly NOT " ". Your query will not work if you put the wrong thing for the table name. The people trying to help you cannot do so if you tell them 2 different things as fact.
 
Last edited:
Thank you all for your help and support.

The following code now works

Option Explicit
Function BuryPostCode()
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT [First Name], " _
& "[Last Name] FROM [Members Contact Details];")
dbs.Close
End Function
Private Sub Command4_Click()
End Sub
Sub postcode()
End Sub
 

Users who are viewing this thread

Back
Top Bottom