[RESOLVED] Have to exit program and re-enter to see the new records added?
Was wondering how to go about making Info update after I add it into the db
Im using vb6.0 and I can add records just fine but when I do it doesnt refresh or update it automaticaly I will have to exit program then re-run and it will be updated? :thumb: thanks again for all your help :thumb:
Re: Have to exit program and re-enter to see the new records added?
How are you adding/editing records? You may try requerying after adding/editing...
Re: Have to exit program and re-enter to see the new records added?
this is what I have Ill try adding the requery to it and see what happens?
thanks again dee-u
vb code------------------------------------------
Private Sub cmdsave_Click()
If dbadd = True Then
Call add
ElseIf dbedit = True Then
Call edit
rs.Update
End If
End Sub
Public Function add()
If txtFirstName.Text = vbNullString Or _
txtLastName.Text = vbNullString Or _
txtSocialSecurity.Text = vbNullString Or _
txtPhone.Text = vbNullString Or _
txtStreet.Text = vbNullString Or _
txtCity.Text = vbNullString Or _
txtState.Text = vbNullString Or _
txtZip.Text = vbNullString Or _
txtID.Text = vbNullString Or _
txtRate.Text = vbNullString Or _
txtGender.Text = vbNullString Or _
txtDateofBirth.Text = vbNullString Or _
txtEmployed.Text = vbNullString Then
errormsg = MsgBox("All Fields Must Contain Data", vbCritical, "Error")
Exit Function
End If
rs.AddNew
rs("FirstName") = txtFirstName.Text
rs("LastName") = txtLastName.Text
rs("SocialSecurity") = txtSocialSecurity.Text
rs("Phone") = txtPhone.Text
rs("Street") = txtStreet.Text
rs("City") = txtCity.Text
rs("State") = txtState.Text
rs("Zip") = txtZip.Text
rs("ID") = txtID.Text
rs("Rate") = txtRate.Text
rs("Gender") = txtGender.Text
rs("DateofBirth") = txtGender.Text
rs("Employed") = txtEmployed.Text
rs.Update
txtFirstName.Text = vbNullString
txtFirstName.Enabled = False
txtLastName.Text = vbNullString
txtLastName.Enabled = False
txtSocialSecurity.Text = vbNullString
txtSocialSecurity.Enabled = False
txtPhone.Text = vbNullString
txtPhone.Enabled = False
txtStreet.Text = vbNullString
txtStreet.Enabled = False
txtCity.Text = vbNullString
txtCity.Enabled = False
txtState.Text = vbNullString
txtState.Enabled = False
txtZip.Text = vbNullString
txtZip.Enabled = False
txtID.Text = vbNullString
txtID.Enabled = False
txtRate.Text = vbNullString
txtRate.Enabled = False
txtGender.Text = vbNullString
txtGender.Enabled = False
txtDateofBirth.Text = vbNullString
txtDateofBirth.Enabled = False
txtEmployed.Text = vbNullString
txtEmployed.Enabled = False
txtSearch.Text = vbNullString
cmdSave.Enabled = False
cmdCancel.Enabled = False
cmdadd.Enabled = True
End Function
Re: Have to exit program and re-enter to see the new records added?
Re: Have to exit program and re-enter to see the new records added?
VB Code:
rs("Employed") = txtEmployed.Text
rs.Update
rs.Requery
Re: Have to exit program and re-enter to see the new records added?
Crazyness I tell you lol
Well Still no go, with that
no errors though
Maybe I can find something that will force a update of the whole table?
again thanks for all the help
Re: Have to exit program and re-enter to see the new records added?
What is rs? A data control? How do you tell that the new records are not reflected?
Re: Have to exit program and re-enter to see the new records added?
rs= recordset
The List box and all my text boxes wont update with the new name entered into the records, It does, strangly enough update into the db when saved but to veiw the new add to the listboxes/textboxes then I have to close whole program and re begin to see the updated record? diesnt this seem odd? I never had this issue arise before?
here are the outside procedures and code for my project the only two things not working so far is the update & also I can't search
sorry for the long code I need to figure out how to put on as a zip
vb-----------------------------------------
Option Explicit
Private db As Database
Private rs As DAO.Recordset
Dim sSQL As String
Private ws As Workspace
Private max As Long
Private i As Long
Private errormsg
Private dbadd As Boolean
Private dbedit As Boolean
Private Sub Form_Load()
sSQL = "SELECT * from EMPDATA "
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(App.Path & "\EmployeeData.mdb")
Set rs = db.OpenRecordset(sSQL)
list
End Sub
Private Function list()
If rs.RecordCount = 0 Then
errormsg = MsgBox("No Records Found", , "Error")
If Len(txtSearch.Text) > 0 Then
txtSearch.Text = Mid(txtSearch.Text, 1, Len(txtSearch.Text) - 1)
Else
Exit Function
End If
End If
rs.MoveLast
rs.MoveFirst
max = rs.RecordCount
rs.MoveFirst
For i = 1 To max
listData.AddItem rs("FirstName") & rs("LastName")
rs.MoveNext
Next i
End Function
Private Sub listData_Click()
Set rs = db.OpenRecordset("Select * from EMPDATA where FirstName & LastName = '" & Trim(listData.list(listData.ListIndex)) & "'")
rs.MoveFirst
txtFirstName.Text = rs("FirstName")
txtLastName.Text = rs("LastName")
txtSocialSecurity.Text = rs("SocialSecurity")
txtPhone.Text = rs("Phone")
txtStreet.Text = rs("Street")
txtCity.Text = rs("City")
txtState.Text = rs("State")
txtZip.Text = rs("Zip")
txtID.Text = rs("ID")
txtRate.Text = rs("Rate")
txtGender.Text = rs("Gender")
txtDateofBirth.Text = rs("DateofBirth")
txtEmployed.Text = rs("Employed")
cmdEdit.Enabled = True
cmdDelete.Enabled = True
End Sub
Private Sub cmdDelete_Click()
errormsg = MsgBox("Are You Sure You Want To Delete This Record", vbYesNo, "Delete Record")
If errormsg = vbYes Then
rs.Delete
Set rs = db.OpenRecordset("EMPDATA", dbOpenTable)
list
txtFirstName.Text = vbNullString
txtFirstName.Enabled = False
txtLastName.Text = vbNullString
txtLastName.Enabled = False
txtSocialSecurity.Text = vbNullString
txtSocialSecurity.Text = False
txtPhone.Text = vbNullString
txtPhone.Enabled = False
txtStreet.Text = vbNullString
txtStreet.Text = False
txtCity.Text = vbNullString
txtCity.Text = False
txtState.Text = vbNullString
txtState.Text = False
txtZip.Text = vbNullString
txtZip.Text = False
txtID.Text = vbNullString
txtID.Text = False
txtRate.Text = vbNullString
txtRate.Text = False
txtGender.Text = vbNullString
txtGender.Text = False
txtDateofBirth.Text = vbNullString
txtDateofBirth.Text = False
txtEmployed.Text = vbNullString
txtEmployed.Text = False
txtSearch.Text = vbNullString
cmdSave.Enabled = False
cmdCancel.Enabled = False
cmdadd.Enabled = True
Else
Exit Sub
End If
End Sub
Private Sub cmdAdd_Click()
txtFirstName.Text = vbNullString
txtLastName.Text = vbNullString
txtSocialSecurity.Text = vbNullString
txtPhone.Text = vbNullString
txtStreet.Text = vbNullString
txtCity.Text = vbNullString
txtState.Text = vbNullString
txtZip.Text = vbNullString
txtID.Text = vbNullString
txtRate.Text = vbNullString
txtGender.Text = vbNullString
txtDateofBirth.Text = vbNullString
txtEmployed.Text = vbNullString
txtFirstName.Enabled = True
txtLastName.Enabled = True
txtSocialSecurity.Enabled = True
txtPhone.Enabled = True
txtStreet.Enabled = True
txtCity.Enabled = True
txtState.Enabled = True
txtZip.Enabled = True
txtID.Enabled = True
txtRate.Enabled = True
txtGender.Enabled = True
txtDateofBirth.Enabled = True
txtEmployed.Enabled = True
cmdadd.Enabled = False
cmdDelete.Enabled = False
cmdEdit.Enabled = False
cmdSave.Enabled = True
cmdCancel.Enabled = True
dbadd = True
End Sub
Private Sub cmdsave_Click()
If dbadd = True Then
Call add
ElseIf dbedit = True Then
Call edit
rs.Update
End If
End Sub
Public Function add()
If txtFirstName.Text = vbNullString Or _
txtLastName.Text = vbNullString Or _
txtSocialSecurity.Text = vbNullString Or _
txtPhone.Text = vbNullString Or _
txtStreet.Text = vbNullString Or _
txtCity.Text = vbNullString Or _
txtState.Text = vbNullString Or _
txtZip.Text = vbNullString Or _
txtID.Text = vbNullString Or _
txtRate.Text = vbNullString Or _
txtGender.Text = vbNullString Or _
txtDateofBirth.Text = vbNullString Or _
txtEmployed.Text = vbNullString Then
errormsg = MsgBox("All Fields Must Contain Data", vbCritical, "Error")
Exit Function
End If
rs.AddNew
rs("FirstName") = txtFirstName.Text
rs("LastName") = txtLastName.Text
rs("SocialSecurity") = txtSocialSecurity.Text
rs("Phone") = txtPhone.Text
rs("Street") = txtStreet.Text
rs("City") = txtCity.Text
rs("State") = txtState.Text
rs("Zip") = txtZip.Text
rs("ID") = txtID.Text
rs("Rate") = txtRate.Text
rs("Gender") = txtGender.Text
rs("DateofBirth") = txtGender.Text
rs("Employed") = txtEmployed.Text
rs.Update
rs.Requery
txtFirstName.Text = vbNullString
txtFirstName.Enabled = False
txtLastName.Text = vbNullString
txtLastName.Enabled = False
txtSocialSecurity.Text = vbNullString
txtSocialSecurity.Enabled = False
txtPhone.Text = vbNullString
txtPhone.Enabled = False
txtStreet.Text = vbNullString
txtStreet.Enabled = False
txtCity.Text = vbNullString
txtCity.Enabled = False
txtState.Text = vbNullString
txtState.Enabled = False
txtZip.Text = vbNullString
txtZip.Enabled = False
txtID.Text = vbNullString
txtID.Enabled = False
txtRate.Text = vbNullString
txtRate.Enabled = False
txtGender.Text = vbNullString
txtGender.Enabled = False
txtDateofBirth.Text = vbNullString
txtDateofBirth.Enabled = False
txtEmployed.Text = vbNullString
txtEmployed.Enabled = False
txtSearch.Text = vbNullString
cmdSave.Enabled = False
cmdCancel.Enabled = False
cmdadd.Enabled = True
End Function
Private Sub cmdEdit_Click()
txtFirstName.Enabled = True
txtLastName.Enabled = True
txtSocialSecurity.Enabled = True
txtPhone.Enabled = True
txtStreet.Enabled = True
txtCity.Enabled = True
txtState.Enabled = True
txtZip.Enabled = True
txtID.Enabled = True
txtRate.Enabled = True
txtGender.Enabled = True
txtDateofBirth.Enabled = True
txtEmployed.Enabled = True
cmdadd.Enabled = False
cmdDelete.Enabled = False
cmdEdit.Enabled = False
cmdSave.Enabled = True
cmdCancel.Enabled = True
dbedit = True
End Sub
Public Function edit()
If txtFirstName.Text = vbNullString Or _
txtLastName.Text = vbNullString Or _
txtSocialSecurity.Text = vbNullString Or _
txtPhone.Text = vbNullString Or _
txtStreet.Text = vbNullString Or _
txtCity.Text = vbNullString Or _
txtState.Text = vbNullString Or _
txtZip.Text = vbNullString Or _
txtID.Text = vbNullString Or _
txtRate.Text = vbNullString Or _
txtGender.Text = vbNullString Or _
txtDateofBirth.Text = vbNullString Or _
txtEmployed.Text = vbNullString Then
errormsg = MsgBox("All Fields Must Contain Data", vbCritical, "Error")
Exit Function
End If
rs.edit
rs("FirstName") = txtFirstName.Text
rs("LastName") = txtLastName.Text
rs("SocialSecurity") = txtSocialSecurity.Text
rs("Phone") = txtPhone.Text
rs("Street") = txtStreet.Text
rs("City") = txtCity.Text
rs("State") = txtState.Text
rs("Zip") = txtZip.Text
rs("ID") = txtID.Text
rs("Rate") = txtRate.Text
rs("Gender") = txtGender.Text
rs("DateofBirth") = txtDateofBirth.Text
rs("Employed") = txtEmployed.Text
rs.Update
txtFirstName.Text = vbNullString
txtFirstName.Enabled = False
txtLastName.Text = vbNullString
txtLastName.Enabled = False
txtSocialSecurity.Text = vbNullString
txtSocialSecurity.Enabled = False
txtPhone.Text = vbNullString
txtPhone.Enabled = False
txtStreet.Enabled = False
txtCity.Text = vbNullString
txtCity.Enabled = False
txtState.Text = vbNullString
txtState.Enabled = False
txtZip.Text = vbNullString
txtZip.Enabled = False
txtID.Text = vbNullString
txtID.Enabled = False
txtRate.Text = vbNullString
txtRate.Enabled = False
txtGender.Text = vbNullString
txtGender.Enabled = False
txtDateofBirth.Text = vbNullString
txtDateofBirth.Enabled = False
txtEmployed.Text = vbNullString
txtEmployed.Enabled = False
txtSearch.Text = vbNullString
cmdSave.Enabled = False
cmdCancel.Enabled = False
cmdadd.Enabled = True
Set rs = db.OpenRecordset("EMPDATA", dbOpenTable)
End Function
Private Sub cmdcancel_Click()
txtFirstName.Text = vbNullString
txtFirstName.Enabled = False
txtLastName.Text = vbNullString
txtLastName.Enabled = False
txtSocialSecurity.Text = vbNullString
txtSocialSecurity.Enabled = False
txtPhone.Text = vbNullString
txtPhone.Enabled = False
txtStreet.Enabled = False
txtCity.Text = vbNullString
txtCity.Enabled = False
txtState.Text = vbNullString
txtState.Enabled = False
txtZip.Text = vbNullString
txtZip.Enabled = False
txtID.Text = vbNullString
txtID.Enabled = False
txtRate.Text = vbNullString
txtRate.Enabled = False
txtGender.Text = vbNullString
txtGender.Enabled = False
txtDateofBirth.Text = vbNullString
txtDateofBirth.Enabled = False
txtEmployed.Text = vbNullString
txtEmployed.Enabled = False
txtSearch.Text = vbNullString
cmdSave.Enabled = False
cmdCancel.Enabled = False
cmdadd.Enabled = True
Set rs = db.OpenRecordset("EMPDATA", dbOpenTable)
End Sub
Private Sub cmdSearch_Click()
If txtSearch.Text = vbNullString Then
sSQL = "SELECT * from EMPDATA "
Set rs = db.OpenRecordset(sSQL)
Else
Set rs = db.OpenRecordset("SELECT * FROM EMPDATA WHERE ID LIKE '" & txtSearch.Text & "*'")
End If
End Sub
Re: Have to exit program and re-enter to see the new records added?
It seems you are not re-populating after adding/editing, try the ff...
VB Code:
Private Sub cmdsave_Click()
If dbadd = True Then
Call Add
ElseIf dbedit = True Then
Call edit
rs.Update
End If
rs.Requery
List
End Sub
Re: Have to exit program and re-enter to see the new records added?
Talk about tripping over a needle in a haystack, and running into a pot o gold at the same time lol
I needed to "list" to display it I think i accidently deleted a few things wile toyin around with different procedures. I can search now too, by Employee ID but the strange thing is , is that I can only do a successful search by id wile the text in enabled = false?
is this wierd to you ?
a little clearer would be to say when press add or cancel this will enable = false my texboxes and only then can i perform a successful search? If I do wile the text is normal then ill get a error I placed "record not found"??
thanks again for all the help!!
Re: [RESOLVED] Have to exit program and re-enter to see the new records added?
Something like this?
VB Code:
Private Sub cmdSearch_Click()
If txtFirstName.Enabled = False Then
If txtSearch.Text = vbNullString Then
sSQL = "SELECT * from EMPDATA "
Set rs = db.OpenRecordset(sSQL)
Else
Set rs = db.OpenRecordset("SELECT * FROM EMPDATA WHERE ID LIKE '" & txtSearch.Text & "*'")
End If
Else
End If
End Sub