A couple of real newbie questions!

Kavy

Well-known Member
Joined
Jun 25, 2007
Messages
607
Hello all!
I am using Access 2007. I want to use user forms to enter my data into the tables, blank ones starting from scratch. I have set up my tables already.

1st Question - I cant find a simple answer to this, how the heck do I add data to a table? Lets say i have a textbox call txtbox and a command call cmd. When the user hits the command what is the syntax to load that text into a table called "Job List" in a database called "life"?


This is what I have so far, any tips?

<code>
dim joblist as tabledef
dim life as Database
dim rsMyrs as recordset

set life = opendatabase("lifea.accdb")
Set rsMyrs = life.openrecordset("job list", dbopendynaset)

</code>

That works, but I am lost from there!

Question 2 - The database is in the same project, do I still have to connect to it?

Question 3 - Whats with this "set focus" stuff? In VB I never had to do that, why do I have to do it now? If I have a command that uses if, elseif statments to check if all my textbox's have data in them, I have to use mutiple if statments and re-set my focus before each statment??


Thanks for any help!

Kavy
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
K i couldnt find the edit function so this will do

Question 1 is down, I got it good, the other 2 are more or less if anyoner knows any shorcuts!
 
Upvote 0
I saw your 2nd post after writing this. I figure something in here will be helpful.
For Question 1, you can do this either through vba or a macro. For vba try the following.

  • Create an append query. Go to the control panel that lists Tables, Queries, Forms, etc., click on Queries, click on New, select "job list" table, click OK, click on View, click on SQL View, and modify the sql so that it looks something like below:
    Code:
    INSERT INTO [job list] ( [FieldName1], [FieldName2], [FieldName3] )
    SELECT [Forms]![YourFormName]![FormFieldName1] AS Expr1, [Forms]![YourFormName]![FormFieldName1] AS Expr2, [Forms]![YourFormName]![FormFieldName1] AS Expr3;
    If you are also inserting entries from a table then you will have to remove ";" at the end and add the sql to the end of above sql statement:
    Code:
    FROM [Your Other Table Name];
  • Replace your vba code with vba code below. You will note some of your previous lines are missing.
    Code:
    Sub AppendJoblist()
    
    dim life as Database
    dim qdProcess As QueryDef
    
    set life = opendatabase("lifea.accdb")
    'You could alternatively use the line below
    'Set life = CurrentDB()
    Set qdProcess = life.QueryDefs("NameOfYourAppendQuery")
    qdProcess.Execute
    
    End Sub
  • Go to your form, click on View, click on Design View, right click on your command button, click on Properties, click on Event tab, click to the right of On Click, and type in, AppendJoblist. Click on View, click on Form View. Enter data in your form and click on the button to test.

For question 2, if you are using a database object, as far as I know, you have have to tell it which one. You can use the shortcut code:
Code:
Set life = CurrentDB()

For question 3, if you have multiple windows/forms/etc. open, the "set focus" stuff, once set, tells code which window or part of an object to do its actions on.

Hope this helps
 
Last edited:
Upvote 0
Well that macro sure helps, makes my life easier on first glance.

The curent db i wil have to try.

The set focus thing, I dont understand. If i am referacning a textbox by its name, in Vb thats enough "focus" if its on the same form as the command button which has the code, why isnt it here?

Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top