Connecting Tech Pros Worldwide Help | Site Map

Inserting Field Values Using VBA

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 07:52 AM
keith@s116160440.onlinehome.us
Guest
 
Posts: n/a
Default Inserting Field Values Using VBA

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, 07:52 AM
keith@s116160440.onlinehome.us
Guest
 
Posts: n/a
Default 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, 07:54 AM
keith@s116160440.onlinehome.us
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.