Command Button

still_rookie

Registered User.
Local time
Today, 14:06
Joined
Apr 17, 2005
Messages
122
hey guys...

is there a VB code by which i can tell a command button to add a new record in a specific table ???
 
Empty record or record with actual data? Is the table bound to the form? You may be able to use the DoCmd.GotoRecord , , acNewRec method.


Also, I moved this thread here as you posted it in the section for people to post useful code samples - didn't the thread called Please Read Before Posting atop that forum give you any hints? ;)
 
oh sorry about that... i read it but ddn't quite get wat it really meant... :) .. but anyway..

i want it this way..
(an example)

when a new employee arrives, the person using the FORM will press 'add new employee' ... and i wanted a window to open allowing him to choose which table to put in........ because i dont want this FORM to be affiliated in any way (except the command button) with the tables .. as it will be the MAIN FORM i.e. this will open when acceess starts...

thanks!
 
I paused a minute reading your last post because it's unusual to have more than one table holding employee data in most databases -- but without knowing more about your particular DB, I can't really say what's what.

So to answer your question: You might want to consider creating a form for each table. Then create yet another form that acts as the middle man -- with a bunch of buttons, each button "pointing" to a different form that is bound to a different table (or, usually better, a query).

If you use the Access wizard when creating the command buttons, it will write the Open Form code for you...

Regards,
Tim
 
pono1 said:
So to answer your question: You might want to consider creating a form for each table. Then create yet another form that acts as the middle man -- with a bunch of buttons, each button "pointing" to a different form that is bound to a different table (or, usually better, a query).
Tim

Thats exactly wat i did. But what i want is a button which will ask the user which table to put the record in when clicked, followed by the record being placed in the table chosen.
 
ok, to help you guys further, this is the code of my command button to add a new record (new employee in this case):
Code:
Private Sub cmdnewemployee_Click()
On Error GoTo Err_cmdnewemployee_Click


    DoCmd.GoToRecord , , acNewRec

Exit_cmdnewemployee_Click:
    Exit Sub

Err_cmdnewemployee_Click:
    MsgBox Err.Description
    Resume Exit_cmdnewemployee_Click
    
End Sub

Now can some one please tell me how and what to edit in this code, sothat a window pops-up asking which table to put the record(employee) into.

if you guys dont get what im saying please dont hessitate to ask.

thanks so much !
 
The record source of the form should be set to the desired table before you call for a new record.

Your quest does not make sense. Why isn't your form's record source [SQL] already set to a table?
 
actually... forget it... can anyone, please tell me whats wrong with this code???

Code:
Option Compare Database

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click


    DoCmd.GoToRecord , , acNewRec

Exit_Command1_Click:
    Exit Sub

Err_Command1_Click:
    MsgBox Err.Description
    Resume Exit_Command1_Click
    
End Sub

Private Sub Command2_Click()
Frame6.Visible = True
End Sub

Private Sub Command20_Click()
If Option8.Value = True Then
Accidents.Show
End If
If Option10.Value = True Then
Car Details.Show
End If
If Option12.Value = True Then
Employee Details.Show
End If
If Option14.Value = True Then
Fuel Details.Show
End If
If Option16.Value = True Then
Service.Show
End If
If Option18.Value = True Then
Transaction.Show
End If
End Sub

im trying to create a frame that will open up when i click on command2. then, when i click on one of the 5 option button and click on command20, that form will open up... But it says to debug...

help please... :o
 

Users who are viewing this thread

Back
Top Bottom