Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Database & Reporting

Post new topic   Reply to topic
Wierd Problem
View previous topic :: View next topic  
Author Message
KaleKYlssen
Newbie


Joined: 31 Jan 2004
Posts: 19

PostPosted: Mar 10th, 2004 10:15 AM    Post subject: Wierd Problem Reply with quote

Hi i was hoping someone would be able to see if there are any errors in this code. The program updates a database from vb, but depending on number of records returned from a sql query it either updates an existing record or adds a new one.The reason i ask is that my program was working fine a few weeks ago but when it came to the start of march it started playing up, it no doesn't return any records from the database even though they are ther, consequently it means that the record count is 0 when it should be 1. I made no changes to code (that i know of). The data entry is controlled by the user selecting a satff id from a combo and the value of a textbox which automatically holds the date of the start of the week. I hope i explained it clear enough, as this is really puzzling me.

Code:

connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\Elco.mdb"
sqlefficiency = "SELECT * FROM Efficiency WHERE  StaffID = '" & cboStaff.Text & "' AND WeekStarting = #" & txtWeek.Text & "#"
rsefficiency.Open sqlefficiency, connstring, adOpenKeyset, adLockOptimistic, adCmdText

rsStock.Open
With rsStock
    IntUn = CInt(rsStock.Fields("Assembled Stock"))
    IntAs = CInt(rsStock.Fields("Unassembled Stock"))
    .Fields("Assembled Stock") = IntUn + Val(txtAmountMade.Text)
    .Fields("Unassembled Stock") = IntAs - Val(txtAmountMade.Text)
    .Update
    .Close
End With

If cboStaff.Text = "" Or cboMotorTYpe.Text = "" Or txtTimeTaken.Text = "" Or txtAmountMade.Text = "" Then
    MsgBox "One or more fields are empty please make a selection", vbOKOnly, "Data Missing"
Else
    If IsNumeric(txtAmountMade.Text) = False Then
        MsgBox "Data Entered is of wrong data type please check", vbOKOnly, "Input Error"
    Else
        If IsNumeric(txtTimeTaken.Text) = False Then
            MsgBox "Data Entered is of wrong data type please check", vbOKOnly, "Input Error"
        Else
            If txtAmountMade.Text <= 0 Or txtAmountMade.Text > 500 Or txtTimeTaken.Text < 0 Or txtTimeTaken > 500 Then
                MsgBox "Data entered is out of accepted range, please check and try again", vbOKOnly, "Input Error"
            Else
If rsefficiency.RecordCount = 0 Then
    With rsefficiency
        .AddNew
        .Fields("WeekStarting") = txtWeek.Text
        .Fields("StaffId") = cboStaff.Text
        .Fields("MotorsMade") = Val(txtAmountMade.Text)
        .Fields("TimeTaken") = Val(txtTimeTaken.Text)
        .Update
        MsgBox "New record has been added", vbOKOnly, "New Record"
        .Close
    End With
Else
    With rsefficiency
        IntTime = CInt(rsefficiency.Fields("TimeTaken"))
        IntMotor = CInt(rsefficiency.Fields("MotorsMade"))
        .Fields("TimeTaken") = IntTime + Val(txtTimeTaken.Text)
        .Fields("MotorsMade") = IntMotor + Val(txtAmountMade.Text)
        .Update
        MsgBox "Record Updated", vbInformation, "Update Successful"
        .Close
    End With

End If
txtTimeTaken.Text = ""
txtAmountMade.Text = ""
End If
End If
End If
End If


This is the code used to put th date in the textbox

Code:

MondayDate = DateAdd("d", -Weekday(Date) + 2, Date)
txtWeek.Text = MondayDate
Back to top
View user's profile Send private message Send e-mail
pradeep
Newbie


Joined: 08 Oct 2003
Posts: 14
Location: INDIA

PostPosted: Mar 12th, 2004 04:36 AM    Post subject: Reply with quote

Change query like this...


sqlefficiency = "SELECT * FROM Efficiency WHERE StaffID = '" & cboStaff.Text & "' AND WeekStarting = #" & Format(txtWeek.Text,"mm/dd/yyyy") & "#"

OR

sqlefficiency = "SELECT * FROM Efficiency WHERE StaffID = '" & cboStaff.Text & "' AND WeekStarting = " & CLng(CDate(txtWeek.Text))
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Database & Reporting All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic