Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: VB Error

Geek News

VB Error
h3llz 12/8/2008 9:51:01 PM
The error must be the loop because Access just crashes when the loop is on, i
use the loop in other Subs, also productQuantity is 45.

Any suggestions?


Sub chkDelete_Click()
Dim Mydb As DAO.database
Dim QryDat As DAO.Recordset
Set Mydb = CurrentDb()

productID.SetFocus
productID = productID.Text
txtQuantity.SetFocus
DoCmd.RunSQL ("INSERT INTO tblProductsLog
(productID,quantity,[timestamp]) VALUES (" & productID & "," &
txtQuantity.Value & ",'" & Now() & "');")

Set QryDat = Mydb.OpenRecordset("SELECT quantity FROM
qryProductsWithQuantity WHERE productID=" & txtProductID.Caption & ";")
QryDat.MoveFirst
txtProductQuantity.Caption = QryDat.Fields.Item("quantity")
cmoSelectQuantity.RowSource = ""
i = "0"
productQuantity = txtProductQuantity.Caption
MsgBox productQuantity
Do While i <= productQuantity
cmoSelectQuantity.AddItem i
i = (i + 1)
Loop
cmoSelectQuantity.SetFocus
productQuantity = cmoSelectQuantity.Value
cmoSelectQuantity.Value = "0"

Form.Requery
Mydb.Close
Set Mydb = Nothing
Set QryDat = Nothing
End Sub
RE: VB Error
Dorian 12/8/2008 11:41:02 PM
Try
Dim i as integer
i = 0 ' not i = "0"

-Dorian

"h3llz" wrote:

[Quoted Text]
> The error must be the loop because Access just crashes when the loop is on, i
> use the loop in other Subs, also productQuantity is 45.
>
> Any suggestions?
>
>
> Sub chkDelete_Click()
> Dim Mydb As DAO.database
> Dim QryDat As DAO.Recordset
> Set Mydb = CurrentDb()
>
> productID.SetFocus
> productID = productID.Text
> txtQuantity.SetFocus
> DoCmd.RunSQL ("INSERT INTO tblProductsLog
> (productID,quantity,[timestamp]) VALUES (" & productID & "," &
> txtQuantity.Value & ",'" & Now() & "');")
>
> Set QryDat = Mydb.OpenRecordset("SELECT quantity FROM
> qryProductsWithQuantity WHERE productID=" & txtProductID.Caption & ";")
> QryDat.MoveFirst
> txtProductQuantity.Caption = QryDat.Fields.Item("quantity")
> cmoSelectQuantity.RowSource = ""
> i = "0"
> productQuantity = txtProductQuantity.Caption
> MsgBox productQuantity
> Do While i <= productQuantity
> cmoSelectQuantity.AddItem i
> i = (i + 1)
> Loop
> cmoSelectQuantity.SetFocus
> productQuantity = cmoSelectQuantity.Value
> cmoSelectQuantity.Value = "0"
>
> Form.Requery
> Mydb.Close
> Set Mydb = Nothing
> Set QryDat = Nothing
> End Sub
RE: VB Error
Maurice 12/9/2008 8:51:00 AM
and to top it of (as an addition to Dorian's reply) make sure you declare i so:

dim i as integer

hth
--
Maurice Ausum


"h3llz" wrote:

[Quoted Text]
> The error must be the loop because Access just crashes when the loop is on, i
> use the loop in other Subs, also productQuantity is 45.
>
> Any suggestions?
>
>
> Sub chkDelete_Click()
> Dim Mydb As DAO.database
> Dim QryDat As DAO.Recordset
> Set Mydb = CurrentDb()
>
> productID.SetFocus
> productID = productID.Text
> txtQuantity.SetFocus
> DoCmd.RunSQL ("INSERT INTO tblProductsLog
> (productID,quantity,[timestamp]) VALUES (" & productID & "," &
> txtQuantity.Value & ",'" & Now() & "');")
>
> Set QryDat = Mydb.OpenRecordset("SELECT quantity FROM
> qryProductsWithQuantity WHERE productID=" & txtProductID.Caption & ";")
> QryDat.MoveFirst
> txtProductQuantity.Caption = QryDat.Fields.Item("quantity")
> cmoSelectQuantity.RowSource = ""
> i = "0"
> productQuantity = txtProductQuantity.Caption
> MsgBox productQuantity
> Do While i <= productQuantity
> cmoSelectQuantity.AddItem i
> i = (i + 1)
> Loop
> cmoSelectQuantity.SetFocus
> productQuantity = cmoSelectQuantity.Value
> cmoSelectQuantity.Value = "0"
>
> Form.Requery
> Mydb.Close
> Set Mydb = Nothing
> Set QryDat = Nothing
> End Sub
Re: VB Error
"Mike Painter" <mddotpainter[ at ]sbcglobal.net> 12/9/2008 6:16:08 PM
Maurice wrote:

[Quoted Text]
>> txtProductQuantity.Caption = QryDat.Fields.Item("quantity")
>> cmoSelectQuantity.RowSource = ""
>> i = "0"
>> productQuantity = txtProductQuantity.Caption
>> MsgBox productQuantity
>> Do While i <= productQuantity
>> cmoSelectQuantity.AddItem i
>> i = (i + 1)
>> Loop
>> cmoSelectQuantity.SetFocus
>> productQuantity = cmoSelectQuantity.Value
>> cmoSelectQuantity.Value = "0"
>>
What am I missing?
It looks like when i = productQuantity , cmoSelectQuantity = i =
productQuantity
at which point productQuantity = cmoSelectQuantity.Value which sets it
equal to itself.
It seems to get thre in a round about way and unless there is a
table1!productquantity and a table2!productquantity, it was there to start
with???


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net