Problem with inserting new records

Aleni

Registered User.
Local time
Today, 07:10
Joined
Dec 6, 2012
Messages
45
Hi everyone!
I have a confirm button in my form which will enter new records in a table and also update another table.
It gives an error if user clicks on button without typing anything in text box.
It was working fine but now its not working.
Its not giving an error,not inserting any records and not even updating table.
I don't have any idea about this.
Can anyone help me with this?
Here is my code:

If IsNull(txtItem) Then
MsgBox "Please fill the required fields", vbInformation

End If
Exit Sub

Issueqty = Me.txtQty
leftQty = curQty - Issueqty
' MsgBox (curQty)
' MsgBox (Issueqty)
' MsgBox (leftQty)

If curQty < 1 Then
MsgBox "Sory There is no item in the inventory", vbInformation
Else

strsql = "Are you sure you want to issue the selected item?"

strsql = MsgBox(strsql, vbYesNo, vbDefaultButton2)

If strsql = vbYes Then
Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset

strsql = "UPDATE tblAcqDetails SET fldQty = " & leftQty & " WHERE fkItemID=" & Forms!frmIssue.txtItemID
rs.Open strsql, cnn, adOpenDynamic, adLockOptimistic
'rs.Update
'rs.Requery
' MsgBox (strsql)

strsql = "SELECT * FROM tblStockTake"
rs.Open strsql, cnn, adOpenKeyset, adLockOptimistic

With rs
rs.AddNew
!fkItemID = txtItemID
!fldIssueQty = txtQty
!fldUOM = txtUOM
!fldLocation = txtlocation
!fldCustomer = txtCus
!fldIssueDate = Date
rs.Update
End With

Set rs = Nothing
Set cnn = Nothing
MsgBox ("The selected device is issued")

End If
End If
 
If IsNull(txtItem) Then
MsgBox "Please fill the required fields", vbInformation

End If
Exit Sub
You say leave the sub in the above line both when txtItem is null and when it is not.

The end if is in wrong line/place. :-)
Else show the error message.
 
Last edited:
There is no error message.
 
The end if is in wrong line. :-)
 
Hi JHB!
Thank you for your help but i tried to placed end if after exit sub but its not working.
If IsNull(txtItem) Then
MsgBox "Please fill the required fields", vbInformation

Exit Sub
End if


I even tried with else,still its not working.
When i try with else statement its giving error saying "invalid use of null" and the error focus on "Issueqty = Me.txtQty" statement.
If IsNull(txtItem) Then
MsgBox "Please fill the required fields", vbInformation

Exit Sub
else
Issueqty = Me.txtQty

'
'
'
End if

Thank you.
thank you
 
It is telling that Me.txtQty not value has.

What du you declare Issueqty and leftQty as?
 
If I code like above it's not giving any error message.
But if i code like below it says "invalid use of null"
IssueQty and leftQty are declared as integer in module.

Thank you.
 
If I code like above it's not giving any error message.
But if i code like below it says "invalid use of null"
IssueQty and leftQty are declared as integer in module.

Thank you.

No because in your first code, you'll never come down to this line because you leave the sub before.
Code:
[I] If IsNull(txtItem) Then
        MsgBox "Please fill the required fields", vbInformation
         
End If
[SIZE=4][B]Exit Sub '[/B][/SIZE]    [/I][I]You say, [B]leave[/B] the sub [B]both[/B] when [/I][I]txtItem is null and when it is [/I]not.
Put in a breakpoint in your code and step through it when the code execute, then you'll see it.
 
Okay I understood it's not correct code.
Can you please help me the correct code.
 
Ok - Either remove "Exit Sub" or else put it in the If - End if statement
 
Thank you JBH.
Its working fine now.
Actually it wasn't txtItem, it was txtQty :) and also I put Exit sub in IF - End if statement.
Thank you.
 

Users who are viewing this thread

Back
Top Bottom