473,387 Members | 1,465 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,387 software developers and data experts.

how to send data to a table by using command button

Hi,
I'm new so try to bare with me. I'm using access 2000 and I created a database where the user is prompted to click on a command button and the info that was put on the form is sent to a table. This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdadd_Click()
  2. Dim db As Database
  3. Dim rst As Recordset
  4. Dim strCriteria As String
  5. Dim intPointer As Integer
  6.  
  7. Set dbspushdb = OpenDatabase("push.mdb")
  8. Set rst = dbspushdb.OpenRecordset("Projects", dbOpenDynaset)
  9.  
  10. ' Ensure that key fields are not empty.
  11.  
  12.   If kittyID = "" Or kittyID = " " Then
  13.         MsgBox prompt:="Please Input Kittyhawk Task Number!", _
  14.         buttons:=vbOKOnly + vbExclamation, _
  15.         title:="Vailidation Error"
  16.     kittyID.SetFocus
  17.     Exit Sub
  18.   End If
  19.  
  20.   With rst
  21.  
  22.   ' If key field has been updated, add NEW record else ...
  23.         If .Locked = False Then
  24.             .AddNew
  25.         Else
  26. ' ... find existing record.
  27.             strCriteria = "[kittyID] = " & Projects & ""
  28.             .FindNext strCriteria
  29.             .Edit
  30.        End If
  31.  
  32. ' Update table with form details
  33.     .Edit
  34.     .Fields("kittyID") = kittyID
  35.     .Fields("cboStore") = cboStore
  36.     .Fields("cboManager") = cboManager
  37.     .Fields("ProjectTitle") = ProjectTitle
  38.     .Fields("Jdial") = JdialNumber
  39.     .Field("ProjectDescription") = ProjectDescription
  40.     .Fields("StartDate") = StartDate
  41.     .Fields("EndDate") = EndDate
  42.     .Fields("ProjectOffice") = ProjectOffice
  43.     .Update
  44.   End With
  45.  
  46.   With Projects
  47. ' Refresh List.
  48.     .Requery
  49.     ' Ensure that the record selected in list matches current
  50.     For intPointer = 0 To .ListCount - 1
  51.         If .Column(0, intPointer) = rst.Fields("Projects") Then
  52.             .Selected(intPointer) = True
  53.             Exit For
  54.         End If
  55.     Next intPointer
  56.     .SetFocus
  57.   End With
  58.  
  59.   rst.Close
  60.  
  61.   Projects.Locked = True
  62.  
Please help.
Feb 2 '07 #1
9 5000
Rabbit
12,516 Expert Mod 8TB
If the form's record source is the table and it's open as a dynaset, then you don't have to tell it to update the table with the information. It'll do that automatically as you enter information.
Feb 2 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. ' Update table with form details
  2. .Edit ' this overrides the .AddNew statement - remove it
  3. .Fields("kittyID") = Me.kittyID
  4.     .Fields("cboStore") = Me.cboStore
  5.     .Fields("cboManager") = Me.cboManager
  6.     .Fields("ProjectTitle") = Me.ProjectTitle
  7.     .Fields("Jdial") = Me.JdialNumber
  8.     .Field("ProjectDescription") = Me.ProjectDescription
  9.     .Fields("StartDate") = Me.StartDate
  10.     .Fields("EndDate") = Me.EndDate
  11.     .Fields("ProjectOffice") = Me.ProjectOffice
  12.     .Update
  13.   End With
  14.  
The Me. designates fields on the form. Make sure the control names are correct.

Expand|Select|Wrap|Line Numbers
  1.   With Me.Projects ' assume this is a listbox control name
  2. ' Refresh List.
  3.     .Requery
  4.     ' Ensure that the record selected in list matches current
  5.     For intPointer = 0 To .ListCount - 1
  6. ' if column0 is the bound column then
  7.         If .ItemData(intPointer) = rst.Fields("Projects") Then
  8.             .Selected(intPointer) = True
  9.             Exit For
  10.         End If
  11.     Next intPointer
  12.     .SetFocus
  13.   End With
  14.  
  15.   rst.Close
  16. Set rst = Nothing
  17. Set dbspushdb = Nothing
  18.  
  19.   Projects.Locked = True
  20.  
Feb 3 '07 #3
NeoPa
32,556 Expert Mod 16PB
If the form's record source is the table and it's open as a dynaset, then you don't have to tell it to update the table with the information. It'll do that automatically as you enter information.
As Rabbit says, while it's possible to do all sorts of complicated stuff in VBA in Access, you really would be better advised (unless you know a reason why not, that you've not shared with us) to create a form bound to the underlying recordset (table) and letting Access handle the updates automatically.
Feb 4 '07 #4
Phille
22
Otherwise a simple append query that grabs the info directly from the control will do.
Feb 6 '07 #5
NeoPa
32,556 Expert Mod 16PB
As in post #4, it's possible, but why complicate your life doing it the complicated way when Access provides a natural way of doing it :confused:
Feb 7 '07 #6
As in post #4, it's possible, but why complicate your life doing it the complicated way when Access provides a natural way of doing it :confused:
I have tried it that way but nothing happen. I have a submit button on the form once it is click it does nothing to enter records into the table. I even used the command button wizard but still no luck. I have ask the same question in a different form and some users gave me hints about diming a database and things of that sort which I knew nothing about. So I came here and from that this forum has been very helpful to me with recent questions and quick responses. This is what I have now:

Expand|Select|Wrap|Line Numbers
  1.  Dim db As Database
  2. Dim rst As Recordset
  3. Dim strCriteria As String
  4. Dim intPointer As Integer
  5.  
  6. Set dbspushdb = OpenDatabase("push.mdb")
  7. Set rst = dbspushdb.OpenRecordset("Projects", dbOpenDynaset)
  8.   With rst
  9.  
  10.         If .Locked = False Then
  11.             .AddNew
  12.         Else
  13.        End If
  14.   ' Update table with form details
  15.     .Fields("kittyID") = kittyID
  16.     .Fields("cboStore") = cboStore
  17.     .Fields("cboManager") = cboManager
  18.     .Fields("ProjectTitle") = ProjectTitle
  19.     .Fields("Jdial") = JdialNumber
  20.     .Field("ProjectDescription") = ProjectDescription
  21.     .Fields("StartDate") = StartDate
  22.     .Fields("EndDate") = EndDate
  23.     .Fields("ProjectOffice") = ProjectOffice
  24.     .Update
  25.   End With
  26.  
  27.   rst.Close
  28.   Set rst = Nothing
  29.   Set dbspushdb = Nothing
  30.  
  31.   Projects.Locked = True 
Where do I go from here?
Feb 7 '07 #7
NeoPa
32,556 Expert Mod 16PB
I would suggest trying it the normal way.
Get the Forms wizard to help you create a form bound to your table or query.
Almost all of the extra stuff is then unnecessary.
When you look at what it creates for you, then you will understand better what I'm talking about.
Feb 7 '07 #8
I would suggest trying it the normal way.
Get the Forms wizard to help you create a form bound to your table or query.
Almost all of the extra stuff is then unnecessary.
When you look at what it creates for you, then you will understand better what I'm talking about.
I've tried the wizard command button again. It gives the error that "It can't go to specified record". So what I done to hopefully try to fix the problem was I compact and repair database. Do you think this will help me?
Feb 7 '07 #9
NeoPa
32,556 Expert Mod 16PB
I don't know if you're replying to my post or whether you just clicked on the Reply button to post.
If you haven't read my last post I suggest you do so, or at least let me know that you're not interested in my continued contributions.
If you are actually replying to my post, then I suggest you check it again, as it says to try the Form wizard NOT the command button control wizard.

Please let me know how you get on (or alternatively let us know if you need help to do this).
Feb 7 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Martin | last post by:
There is an Access table on the network. 15 users who do not have Access are connected to the network. Is there a way for each user to be able to enter one or more rows containing 3 or 4 columns to...
3
by: Hasanain F. Esmail | last post by:
Hi, Your help will be greatly appriciated. I have a table with following fields. Table's name is tblTicketNumers TicketNumberID (It is a key field) TicketNumber (Text field) AgentsName (Text...
1
by: Andrew Arace | last post by:
I scoured the groups for some hands on code to perform the menial task of exporting table data from an Access 2000 database to Oracle database (in this case, it was oracle 8i but i'm assuming this...
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
15
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
2
by: mcraven.2 | last post by:
How do you send a browser to a link when a command is given? I've tried using Java Server Pages <jsp:forward /command but that doesn't change the link in the address bar and some other problems...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
7
by: Dave | last post by:
Hello All, These one may be a bit tricky, and what I'd like to do may not even be possible. I would love to hear any ideas you guys have for solving this. Here is the situation: I have a form...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.