By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,483 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,483 IT Pros & Developers. It's quick & easy.

What's Wrong with this code

P: n/a
Hi ppl

the foll: code calls a query that inserts the data into a table through
parameters...
is my sql statement correct... My table is created in design view....
Private Sub Command4_Click
On Error GoTo Err_Command4_Click

Dim count As Integer
Dim qd As QueryDef
Dim strsql As String

strsql = "select nz(max(asset_id),0)+ 1" & "from asset"
Set qd = CurrentDb.QueryDefs("add")
qd.Parameters("parFld1") = strsql
qd.Parameters("parFld2") = Text2
qd.Execute


DoCmd.Close
stDocName = "asset_INFORMATION"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click
End Sub


my query is :

insert into asset (asset_id,asset_level)
values (parfld1,parfld2)
plz help....

Aug 28 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Reiro wrote:
Hi ppl

the foll: code calls a query that inserts the data into a table through
parameters...
is my sql statement correct... My table is created in design view....
Private Sub Command4_Click
On Error GoTo Err_Command4_Click

Dim count As Integer
Dim qd As QueryDef
Dim strsql As String

strsql = "select nz(max(asset_id),0)+ 1" & "from asset"
Set qd = CurrentDb.QueryDefs("add")
qd.Parameters("parFld1") = strsql
qd.Parameters("parFld2") = Text2
qd.Execute


DoCmd.Close
stDocName = "asset_INFORMATION"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click
End Sub


my query is :

insert into asset (asset_id,asset_level)
values (parfld1,parfld2)
plz help....
Is there a reason you are making strSQL a parameter? WHen will you
assign the qd's SQL a value?
Aug 28 '06 #2

P: n/a

hi ... i came up with a solution... i took out the sqlstr and my
insert sataement now looks like this...

insert into asset(asset_id,asset_level)
select nz(max(asset_id),0) + 1,parfld2
from asset;
it works fine.....

Aug 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.