-
June 9th, 2017, 11:54 PM
#1
Run Time Error:91
Code:
Private Sub stock()
Set Record = New ADODB.Recordset
Record.Open "Select * from Stockin where ProductCode='" & TxtDesc.Text & "'", Connect, 1, 3
With Record
If .EOF = True And .BOF = True Then
Else
txtQty.Text = Record!Qty
txtpack.Text = Record!Packing
txtPrice.Text = Record!SalesPrice
Record.Close
Set Record = Nothing
End If
End With
End Sub
Object variable or with block variable not set
-
June 10th, 2017, 07:13 AM
#2
Re: Run Time Error:91
Which line gives the error?
My guess would be that Connect is not set to anything
As I mentioned before Connect and Record are not good choices for object names
You should move that record.close and set record=nothing to after the end if.
If you are going to use a with block you should actually use it but in the code above it is actually only used on one line.
There is also no need to check both eof and bof
Code:
Private Sub stock()
Set Record = New ADODB.Recordset
With Record
.Open "Select * from Stockin where ProductCode='" & TxtDesc.Text & "'", Connect, 1, 3
If Not .EOF Then
txtQty.Text = !Qty
txtpack.Text = !Packing
txtPrice.Text = !SalesPrice
End If
.Close
End With
Set Record = Nothing
End Sub
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|