SPereira 0 Newbie Poster

hi!:(
I'm Ariah,
I got problem with vb 6.0 codes to delete records from tables, w/c I used MS Access 2003 as my database. Can u please help me in coding? just give me a very simple code for this, without using any modules. . . ok? thanks a lot! hope u can help me too. . .
good day!

Refer to the previous posts. After using the Connection.Execute command refresh the Recordset using the ReQuery option.

SPereira 0 Newbie Poster

Hi

I did try the begintrans / committrans but it somehow didn't work out. But the Requery option did work.

Thanks anyway.

SPereira 0 Newbie Poster

Hi Shailaja,

Thanks alot. The ReQuery option did the trick. Now I can move on with ease.

C Ya.

HI,

To Refresh the Recordset you can use the ReQuery which the query executes again to get the proper results.


Shailaja:)

SPereira 0 Newbie Poster

Hi Guys,

I have written a program in VB 6 wherein I want to delete a particular record from MS Access Database Table. I noticed that the record does not get deleted immediately. Only after I close the recordset it disappears. I have a Delete Command Button in a Form that deletes a particular record. After deletion, when I browse the records in the table I noticed that the record has not been deleted. It is only when I close the Form which closes the recordset to that table and when I reopen the recordset I notice that the record gets deleted then. My code is as follows.

Conn.Execute "DELETE FROM <tablename> WHERE FIELD1 = '" & cmdField1.Text & "'"

where Conn is set to a New Connection. So what I did was close the recordset and then reopen it again soon after the above command is executed as follows.

Rs.Close
Rs.Open "SELECT * FROM <tablename> ORDER BY FIELD1", Conn, , , cmdTable

Please let me know if I am doing this the right way or is there any other method of solving this issue? But I want to use the Connection.Execute command only.

Please help. Thanks.
SPereira

SPereira 0 Newbie Poster

one thing you can do. just put a if condition inside your validate event before the code for checking existence of the textbox's value. check if the textbox has null value in it or not. if it don't then fire the code else just exit the sub. like this :-

private sub text1_validate()
if trim(text1.text)<>"" then
   <your code for checking into database>
else  <as the textbox is empty, so there is no need to check for the code into the database
    exit sub
end if
end sub

regards
Shouvik

Hi Shouvik,

Thanks for ur reply. Actually I was doing just that. Only thing was that I had a MsgBox which kept firing when I used to click on a label or a frame. My code read as below

private sub text1_validate(cancel as Boolean)
if trim(text1.text)="" then <as the textbox is empty, so there is no need to check for the code into the database
cancel = true
MsgBox "Enter a Unique Code", vbInformation
else
<your code for checking into database>
end if
end sub

So whenever I used to click on any label or frame where the causesvalidaion cannot be set it used to trigger the MsgBox. So what I've done now is removed the MsgBox and just added an Exit Sub. This should do just fine.

Thanks once again.

SPereira 0 Newbie Poster

you don't need to get the ascii code of TAB to trap the key. just put your code inside the VALIDATE or LOSTFOCUS event of ur textbox. whenever you press the tab key the code will be automatically fired.

Hi Shouvik_The_Expert_Coder

I tried ur option using the validate key but now even if I click on any label or frame the validate option fires. I can set the causesvalidation to false for the command buttons and picture buttons but the labels and frames do not have any causesvalidation event.

My case is like this. I have a table where I am storing some data. The first textbox in the form I use is to enter the code. I need to validate this code and check if this exists in the table or not. So when I press the Enter Key, in the keypress option I check if the record exists. If not then I need to add a New Record using recordset.AddNew. . i.e.

If KeyAscii = 13 then
recordset.movefirst
recordset.find "ACOD = " & "'" & trim(cACod.text) & "'"
'Where cACod.text is the textbox which requires to be validated.
if recordset.EOF then
recordset.AddNew
else
msgbox "Record Exists"
exit sub
endif

The problem arises when I press the Tab Key. The Keypress does not get activated at this instance. Even if I place this condition in the validate option and if I press any label or frame …

SPereira 0 Newbie Poster

try using the TextArray property of MsFlexgrid and determine the contents of the cell if it is not a blank cell then continue with your procedure or else exit sub.

SPereira 0 Newbie Poster

Hi There,

I need some help in VB 6. I have a textbox wherein I need to validate the data entered after the TAB key is pressed. Using KeyDown, KeyUp and KeyPress does not get me the KeyAscii of the Tab Key. It works fine with the Enter Key but the Tab Key doesn't work. Is there any function where I could get the LastKey Pressed so I could place a check on the TAB key in my Validate event. Or is there any other possible way I could try out?