Connecting Tech Pros Worldwide Help | Site Map

Inserting Field Values Using VBA

  #1  
Old November 13th, 2005, 08:52 AM
keith@s116160440.onlinehome.us
Guest
 
Posts: n/a
Thanks to everyone for their previous help, I'm almost finished with my
database. I just need one piece of information, and it should be good
to go!

I'm using a SQL Server database with Access 2003 as a frontend. I have
a button on a form that says "Add Record". When the user clicks that, I
would like to have some fields automatically generated so that I don't
get an error that the main database can't accept null entries. Here's
what I have so far:

Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click


DoCmd.GoToRecord , , acNewRec
Dim sSQL As String
strSQL = "INSERT INTO <Print Jobs> (<NetworkUser>, <MachineName>,
<ProcessName>, <PrinterName>,) VALUES (<Public Rec>, <Server>,
<MSACCESS.EXE>, <MainPrinter>)"
db.Execute strSQL, dbFailOnError

Exit_Add_Record_Click:
Exit Sub

Err_Add_Record_Click:
MsgBox Err.Description
Resume Exit_Add_Record_Click

End Sub


When I run it, it says that an object is required. I'm still new to
VBA, so I don't know what I'm doing wrong as what I have up there was
cobbled from various Usenet posts.

Also, I'd like to enter the date in a date field automatically at the
time of the button press (dd/mm/yy hh:mm:ss). Do I have to do something
different as it's not just straight text like enclosing it in single
quotes?

Thanks for your help!

  #2  
Old November 13th, 2005, 08:52 AM
keith@s116160440.onlinehome.us
Guest
 
Posts: n/a

re: Inserting Field Values Using VBA


Forgot to mention..two of the reasons I need the date to be
automatically entered:

1. I have a query that pulls back results from only that day.
2. I have the date (since it's down to the second) as the primary key.
It's highly unlikely that we'll ever have two events happen at exactly
the same time.

  #3  
Old November 13th, 2005, 08:54 AM
keith@s116160440.onlinehome.us
Guest
 
Posts: n/a

re: Inserting Field Values Using VBA


I found a different way around it, if anyone's interested. I entered a
text box for each necessary field, and set the default value of that
textbox to my specific text. Then, I made those text boxes hidden.
Lastly upon the button press, I have the following code:

DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl "UserDefined1"
Me.DatePrinted = Now
Me.PrinterName = "None"

That way, it fills in the date and adds a printer name as well.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Only two options to import Excel files? PW answers 18 June 27th, 2008 08:25 PM
Mass Import w/Multiple Tables blyxx86 answers 3 September 6th, 2007 10:14 AM
Recordset in subform based on field in parent form Lyn answers 25 November 13th, 2005 12:52 AM
Import/Normalize approach - column-DML, or loop Steve Jorgensen answers 20 November 12th, 2005 07:50 PM