VBA Save Button Question

westerncj

New member
Local time
Today, 11:39
Joined
Jun 10, 2011
Messages
2
I have a save button on my form. I want it to update the record if the SkidID is the same. If it's not the same I want it to insert the new record. The problem I'm having is that the SkidID is the same everytime so it never inserts..Can anyone help me?

Code:
Private Sub btnSave_Click()
    Dim stDocName As String
 
 'Updating the record based off of txtSkidID
If SkidID = txtSkidID.Value Then
fnDoSQL "UPDATE tbl_Inventory SET Status = '" & Trim(cmboStatus) & " ', Location = '" & Trim(cmboLocation) & "'" & _
"WHERE SkidID = " & Trim(txtSkidID) & " "
End If
If txtSkidID.Value <> SkidID Then
'Insert Function
fnDoSQL "INSERT INTO tbl_Inventory (SkidID, Location, Status) VALUES " _
& "('" & Trim(txtSkidID.Value) & "', '" & Trim(cmboLocation.Value) & "', '" & Trim(cmboStatus.Value) & "')"
End If
'Checking to make sure all fields have information in them before you save
    If (IsNull(txtSkidID.Value) = True Or txtSkidID.Value = "" Or IsNull(cmboLocation.Value) = True Or cmboLocation.Value = "" _
    Or IsNull(cmboStatus.Value) = True Or cmboStatus.Value = "") Then
    MsgBox ("All Fields Must Be Complete!")
    End If
End Sub
 
Hi,
Where is the SkidID comes from? is it the Field on your form? why it is always same? Is your form is unbound?
Where do you use the Dim stDocName As String, I think this is unnecessary declaration in your code?
put break point on this line:
If SkidID = txtSkidID.Value Then
and check if it is same/null etc?
 
Yeah SkidID is from my form. I want it to check the SkidID that I have in my table and compare to the one entered on the form.

They are the same everytime when I hover over them.
 
hover over in the code window? just hover over by mouse is not giving the exact value in VBA code sometimes.
you should put break points on the code to analyse if really it is the same?
The best way is to go along with your code line by line and monitor it closely for each line what's going on?
It's difficult to know why SkidID = txtSkidID.Value? From where is the txtSkidID comes? this might be also populating from your SkidID field so its always remain same.
 

Users who are viewing this thread

Back
Top Bottom