Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to execute SQL from a command botton. 1

Status
Not open for further replies.

macfil

Technical User
Sep 14, 2005
15
CA
I have a command botton which I would like to run a SQL.

Private Sub Command3_Click()
Dim SQL As String
SQL = "select * from inv1 where Bin = '13'"
CurrentDb.Execute (SQL)
End Sub

I keep getting an error on CurrentDB.Execute (SQL) highlite in yellow.

What's wrong with this code? Is something missing?
Thanks

 
Hi all
Does not work.
Here is the code I'm using from dhookom

Code:
Function OpenOSBinForm(strBin As String)
    Dim strWhere As String
   ' strWhere = "[Bin]='" & strBin & "'" 'replace with
   
    strWhere = "[Bin]='Like " & strBin & "*'"

    DoCmd.OpenForm "frmOSBins", acFormDS, , strWhere
    
End Function

Now I don't have any error, but I don't get any result except for field name.

Thanks

 
[tt]strWhere = "[Bin][highlight] [/highlight]Like [highlight]'[/highlight]" & strBin & "*'"[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV

I made the correction but it didn't work.
Did not get any error though.

Thanks
 
Could you please post your actual code ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV
Sorry it toke so long to answer. Here's the code.

Code:
Function OpenOSBinForm(strBin As String)
    Dim strWhere As String
   
    strWhere = "[Bin] Like " & strBin & "*'"

    DoCmd.OpenForm "frmOSBins", acFormDS, , strWhere
    
End Function

Thanks
 
Code:
strWhere = "[Bin] Like [COLOR=red yellow]'[/color]" & strBin & "*'"

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
Hi Golom

Sorry it was a typo on my part.
If I ask for 22A, or 22B or just 22, it does work, but what I would need is to see the full section 22. (22, 22A, 22B ...)

Thanks
 
I forgot to mention that I call that funtion from my command button. on Click =OpenOSBinForm("22 ")
=OpenOSBinForm("23 ")
=OpenOSBinForm("24 ") and so on.

I'm still new at this, but learning.
Thanks
 
Get rid of the trailing space:
=OpenOSBinForm("22")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top