-4
Private Sub txtmid_Change()
On Error Resume Next

Mmid = txtmid.Text

Adodc1.RecordSource = "select * from members where txtmid like '" & Mmid & "'"
Adodc1.Refresh

Mname = Adodc1.Recordset.Fields("Mname").Value
Expiryd = Adodc1.Recordset.Fields("Expiryd").Value

txtname.Text = Mname
txtedate(1).Text = Format(Expiryd, "dd / mm / yyyy")
End Sub

I am getting FROM clause error. Please help me to resolve this error. Thank you.

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
Siddhi
  • 1
  • Are you sure that **txtmid** is a field of members table? – Giorgio Brausi May 16 '17 at 19:51
  • @Giorgio : Thanks for the reply. in the database it is Mmid but here on the circulation form text box is txtmid – Siddhi May 17 '17 at 11:58
  • @Siddhi, for the amount of effort you put into your question, I'm not sure you can expect much effort from the StackOverflow community. Code needs to be formatted (someone has done that for you) and your title needs to be useful for someone scanning the list of questions. See [ask]. With that said, try running your select statement manually in whatever database (a tag would help as well) and see what it says. Then fix it. – C-Pound Guru May 17 '17 at 16:30
  • From your comment above the SQL should probably read "SELECT * FROM Members WHERE Mmid LIKE '" & txtmid.text & "'" I think you have the names mixed up. – Slugsie May 18 '17 at 13:42
  • You should _never_, _ever_ form a SQL command using direct user input. Look up using parametrized queries and SQL injection attacks. – xxbbcc May 18 '17 at 21:38

1 Answers1

0

Try this:

First of all, remove On Error Resume Next, because it's dangerous (you should use a very error handler, instead).

Adodc1.RecordSource = "select * from members where Mmid = '" & Mmid & "'"

Note: anyway, for fields of TEXT type, you should use always Replace$() to 'double quote' to avoid mistake when string values contains a single quote. Example:

Dim sql As String
Dim sSearch As String
sSearch = "You are 'magic' developer"
sql = "SELECT * FROM Users WHERE Note = '" & Replace$(sSearch, "'", "''") & "'"

Otherwise, in this case, if you use (wrongly):

sql = "SELECT * FROM Users WHERE Note = '" & sSearch & "'"

You will get a error.

Giorgio Brausi
  • 414
  • 3
  • 7