473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VBA code for adding, deleting and searching for a record.

I am a beginner to the more technical aspects of Microsoft Access
(2000) and was wondering if any one can help. I have 3 buttons on a
form which add, delete and search for a record. However, when I click
on the respective buttons absolutely nothing happens! I was wondering
if anyone could help? The code I have is below...

ADDING A RECORD

Private Sub cmdaddstudent_Click()
On Error GoTo Err_cmdaddstudent_Click
DoCmd.GoToRecord , , acNewRec

Exit_cmdaddstudent_Click:
Exit Sub

Err_cmdaddstudent_Click:
MsgBox Err.Description
Resume Exit_cmdaddstudent_Click

End Sub
DELETING A RECORD

rivate Sub cmddeletestudent_Click()
On Error GoTo Err_cmddeletestudent_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_cmddeletestudent_Click:
Exit Sub

Err_cmddeletestudent_Click:
MsgBox Err.Description
Resume Exit_cmddeletestudent_Click

End Sub
SEARCHING FOR A STUDENT

Private Sub cmdsearchstudent_Click()
On Error GoTo Err_cmdsearchstudent_Click
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_cmdsearchstudent_Click:
Exit Sub

Err_cmdsearchstudent_Click:
MsgBox Err.Description
Resume Exit_cmdsearchstudent_Click

End Sub

There it is! Absolutely no sense to me but any help would be VERY MUCH
appreciated.

Thanks in advance

Matt
Nov 12 '05 #1
7 10738
Matthew,

The first thing to do is to check that the code is actually running. In the
second line of each procedure (you have 3), insert this code:
MsgBox "Hello Matt"

If the message doesn't pop up, your procedure isn't running and you need to
investigate why!

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Mathew Hill" <Co************@hotmail.com> wrote in message
news:1c*************************@posting.google.co m...
I am a beginner to the more technical aspects of Microsoft Access
(2000) and was wondering if any one can help. I have 3 buttons on a
form which add, delete and search for a record. However, when I click
on the respective buttons absolutely nothing happens! I was wondering
if anyone could help? The code I have is below...

ADDING A RECORD

Private Sub cmdaddstudent_Click()
On Error GoTo Err_cmdaddstudent_Click
DoCmd.GoToRecord , , acNewRec

Exit_cmdaddstudent_Click:
Exit Sub

Err_cmdaddstudent_Click:
MsgBox Err.Description
Resume Exit_cmdaddstudent_Click

End Sub
DELETING A RECORD

rivate Sub cmddeletestudent_Click()
On Error GoTo Err_cmddeletestudent_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_cmddeletestudent_Click:
Exit Sub

Err_cmddeletestudent_Click:
MsgBox Err.Description
Resume Exit_cmddeletestudent_Click

End Sub
SEARCHING FOR A STUDENT

Private Sub cmdsearchstudent_Click()
On Error GoTo Err_cmdsearchstudent_Click
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_cmdsearchstudent_Click:
Exit Sub

Err_cmdsearchstudent_Click:
MsgBox Err.Description
Resume Exit_cmdsearchstudent_Click

End Sub

There it is! Absolutely no sense to me but any help would be VERY MUCH
appreciated.

Thanks in advance

Matt

Nov 12 '05 #2
Hi,

Yeah I tried that and a message does appear saying 'Hello Matt'. Can you
think of anything else?

Matt

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
Co************@hotmail.com (Mathew Hill) wrote in message news:<1c*************************@posting.google.c om>...
I am a beginner to the more technical aspects of Microsoft Access
(2000) and was wondering if any one can help. I have 3 buttons on a
form which add, delete and search for a record. However, when I click
on the respective buttons absolutely nothing happens! I was wondering
if anyone could help? The code I have is below...


I just tried your code (except for adding a missing 'P') in Access 97
and in Access 2K. The form had a Record Source of tblData (bound).
All three buttons worked perfectly. I used the minimum number of
'References' allowed by Access. I also tried deleting all the records
from tblData. The 'New' button wouldn't work in that case. The
other buttons reported "You can't use Find or Replace now."
I tried setting the Form Properties 'Allow Edits', 'Allow Deletions'
and 'Allow Additions' to No. This allowed the Search button to
work but the other buttons reported "You can't go to the specified
record." Something very basic is missing.

I would guess that Access has "lost" the connection between the
command button and the code. Go to design mode and double
click one of the command buttons. If you see [Event Procedure]
to the right of the 'On Click . .' then click on it. You should see
three dots to the far right. Single click on the three dots. If you
see your code come up then something else is the problem.

If you don't see [Event Procedure] or your code then Edit | Undo
Insert Text. The code you want for the button should still be
visible. Go to the code you want and use CTRL X from the On
Error to just before the End Sub. Then delete the Sub declaration
line and the End Sub by highlighting and pressing Delete. Go
back to the form design view and double click on that button.
Click the Event tab then click on the white space to the right
of "On Click." You should see three dots on the far right. Single
click on the three dots. If Choose Builder comes up, choose
"Code Builder." This "reconnects" the code to the button.
The code you want should still be in your edit buffer. Paste
the code in again between the Sub Declaration and the End Sub.

This problem can occur when you paste code behind a form
and then create the command buttons afterwards. Sometimes
Access doesn't automatically find the code.

James A. Fortune
Nov 12 '05 #4
James,

Read his response to my suggestion. He says that he gets "Hello Matt" when he
clicks the buttons so the code has to be connected to the buttons. It's got me
stumped!

Steve
PC Datasheet
"James Fortune" <ja******@oakland.edu> wrote in message
news:a6**************************@posting.google.c om...
Co************@hotmail.com (Mathew Hill) wrote in message

news:<1c*************************@posting.google.c om>...
I am a beginner to the more technical aspects of Microsoft Access
(2000) and was wondering if any one can help. I have 3 buttons on a
form which add, delete and search for a record. However, when I click
on the respective buttons absolutely nothing happens! I was wondering
if anyone could help? The code I have is below...


I just tried your code (except for adding a missing 'P') in Access 97
and in Access 2K. The form had a Record Source of tblData (bound).
All three buttons worked perfectly. I used the minimum number of
'References' allowed by Access. I also tried deleting all the records
from tblData. The 'New' button wouldn't work in that case. The
other buttons reported "You can't use Find or Replace now."
I tried setting the Form Properties 'Allow Edits', 'Allow Deletions'
and 'Allow Additions' to No. This allowed the Search button to
work but the other buttons reported "You can't go to the specified
record." Something very basic is missing.

I would guess that Access has "lost" the connection between the
command button and the code. Go to design mode and double
click one of the command buttons. If you see [Event Procedure]
to the right of the 'On Click . .' then click on it. You should see
three dots to the far right. Single click on the three dots. If you
see your code come up then something else is the problem.

If you don't see [Event Procedure] or your code then Edit | Undo
Insert Text. The code you want for the button should still be
visible. Go to the code you want and use CTRL X from the On
Error to just before the End Sub. Then delete the Sub declaration
line and the End Sub by highlighting and pressing Delete. Go
back to the form design view and double click on that button.
Click the Event tab then click on the white space to the right
of "On Click." You should see three dots on the far right. Single
click on the three dots. If Choose Builder comes up, choose
"Code Builder." This "reconnects" the code to the button.
The code you want should still be in your edit buffer. Paste
the code in again between the Sub Declaration and the End Sub.

This problem can occur when you paste code behind a form
and then create the command buttons afterwards. Sometimes
Access doesn't automatically find the code.

James A. Fortune

Nov 12 '05 #5
"PC Datasheet" <sp**@nospam.spam> wrote in message news:<Cj***************@newsread3.news.atl.earthli nk.net>...
James,

Read his response to my suggestion. He says that he gets "Hello Matt" when he
clicks the buttons so the code has to be connected to the buttons. It's got me
stumped!

Steve
PC Datasheet


Yeah, you're absolutely correct. I thought about it about two minutes after
I hit 'Post.' I tried taking out the Record Source and that just kept
the records on the form from showing up. C'mon Matt, give us another hint!
Do you have other forms with code that run properly? Could the files used
by the references be corrupted? I'm running out of options. Are you just
kidding with us? Is your mouse acting flaky :-)? Throw us Access hounds
a bone. Seriously, we need more information to try to tell what's going on.
What version of Access are you using? Did you do a custom installation that
could have omitted something important? Did you used to have a previous
version of Access on your machine. Something strange is going on.

James A. Fortune
Nov 12 '05 #6
Hi

Thank you VERY much for your help. I deleted all the buttons and then
created them again. Now they seem to be working! Very strange!!

I am having trouble with the search button though. I enter a record on a
form and then test that the search button is working by adding the same
search criteria that I have just inputted on my form. But it says it
cant find it. Which is completely stupid because it is obviously there
as I have just inputted it!

Search Code

Private Sub cmdsearchrecord_Click()
On Error GoTo Err_cmdsearchrecord_Click
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_cmdsearchrecord_Click:
Exit Sub

Err_cmdsearchrecord_Click:
MsgBox Err.Description
Resume Exit_cmdsearchrecord_Click

End Sub
If you could help I would be very grateful.

Thanks

Matt

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #7
Here's a sample database from http://www.utteraccess.com

A Wee Improved Search Engine
http://www.utteraccess.com/forums/sh...b=5&o=&fpart=1
Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mathew Hill | last post by:
I am a beginner to the more technical aspects of Microsoft Access (2000) and was wondering if any one can help. I have 3 buttons on a form which add, delete and search for a record. However, when I...
1
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting...
2
by: John | last post by:
Hi I have a master/detail form with detail part being a sub form. My problem is that when a user clicks on the sub form to add a record, this error comes up; "The Microsoft jet database engine...
4
by: JollyK | last post by:
Hello everyone... I have created a user-control that has a fairly complex datagrid (with template columns) which includes localization, custom paging, sorting, filtering, searching, caching,...
2
by: TdarTdar | last post by:
HI, I have a asp 2.0 page that has a sqldatasource and a detailsview i have enabled the inserting updating deleting in the datasoure. I have a blank table that has no records. I run the page.. I...
0
by: Lisa Jones | last post by:
Hi Has anyone see this problem in ADO.Net when deleting a record (assuming that the table has identity increment Index) result in getting wrong index key if right after adding the record the table...
1
by: JohnR | last post by:
I'm using oledb to an Access datatable. I load the table into a dataset. I create databindings to link the fields on my form to the corresponding fields in the datatable. The tables...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
1
by: chriscely | last post by:
Good day to everybody! I have been having this problem for quite a few times already. I have been trying to add informations to our database, the programs on my add page (entry_schedule.asp) is...
1
by: smartchap009 | last post by:
Adding,Updating and Deleting user using perl script in linux -------------------------------------------------------------------------------- hi, If i can get help in writing perl code for...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.