Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
VB

SQL
PARAMETERS [Enter Start Date] DateTime, [Enter End Date] DateTime;
Insert into temptblPlacements
SELECT tblPlacements.*
FROM tblPlacements
WHERE (((tblPlacements.CompDate) Between [Enter Start Date] And [Enter End Date]));


How can I Pass values to this Query from textboxes in MS Access
Posted

1 solution

There are few methods to achieve that, but i need to know the version of Access database...

Running query in form1:
SQL
Insert into temptblPlacements
SELECT tblPlacements.*
FROM tblPlacements
WHERE (((tblPlacements.CompDate) Between #[Forms]![Form1]![TextBox1]# And #[Forms]![Form1]![TextBox2]#));


Running vba code:
VB
Private Sub Button1_Click()
Dim sSQL as String

On Error GoTo Err_Button1_Click

sSQL= "Insert into temptblPlacements" & vbcr & _
    "SELECT tblPlacements.*" & vbcr & _
    "FROM tblPlacements" & vbcr & _
    "WHERE (((tblPlacements.CompDate) Between #" & Me.TextBox1 & "# And #" & Me.TextBox2 & "#));"

CurrentDb.Execute sSQL

Exit_Button1_Click:
    Exit Sub

Err_Button1_Click:
    MsgBox Err.Description, vbExclamation, "Error " & Err.Number
    Resume Exit_Button1_Click
End Sub
 
Share this answer
 
v3
Comments
mmsgk251804 20-Feb-12 1:48am    
VErsion of MS Access is 2003
mmsgk251804 20-Feb-12 2:02am    
For the Same how do I write the Error handler ?
Maciej Los 8-Jun-12 0:53am    
Take a look at my naswer after update.
codeBegin 8-Jun-12 2:17am    
my 5
Maciej Los 8-Jun-12 6:46am    
Thank you ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900