CodeConnect.Net Beta


   Explore    Entry   Register  Login  
windowsxp-general
access
windows-vista-mail
windows-vista-general
windowsupdate
windowsmedia-player
access-forms
windows-live-mail-desktop
windowsxp-help_and_support
access-queries
access-modulesdaovba
access-formscoding
windows-server-sbs
windows-server-general
access-reports
windows-vista-music_pictures_video
windowsce-platbuilder
windows-live-messenger
windows-terminal_services
windows-powershell
windows-server-active_directory
access-gettingstarted
windows-mediacenter
windowsxp-hardware
windowsxp-network_web
windows-64bit-general
windows-live-sync
windows-vista-hardware_devices
windows-inetexplorer-ie6_outlookexpress
windows-group_policy
windows-server-networking
windows-vista-installation_setup
windows-vista-networking_sharing
windowsxp-basics
access-tablesdbdesign
windowsxp-perform_maintain
windows-vista-performance_maintenance
windows-networking-wireless
windows-vista-file_management
windows-inetexplorer-ie6-browser
windows-server-dns
windows-server-update_services
windows-vista-security
windows-vista-administration_accounts_passwords
windows-vista-games
windows-file_system
access-activexcontrol
windows-live-foldershare
windows-live-photogallery
access-developers-toolkitode
access-conversion




Can Reply:  Yes Members Can Edit: No Online: Yes
Zone: > Microsoft News > microsoft.public.access.modulesdaovba Tags:
Item Type: Date Entered: 11/10/2009 5:24:05 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 1 Views: 98 Favorited: 0 Favorite
2 Items, 1 Pages 1 |< << Go >> >|
"al416 via Acce
NewsGroup User
Updating a table from a form and subform11/10/2009 5:24:05 PM
Reply

0

I started this thread in FormsProgramming, but got no response.

Maybe somebody in VBA can help me out
Thanks.

Any help would be appreciated:

I'm trying to add lines to two different tables in two steps. One line to the
first table and multiple lines to the second. The number of lines equals the
same quantity of lines showing in the subform. Step one works fine (first
INSERT INTO stement).

The second doesn't work:
1. The X = ... statement fails. Syntax error?
2. The INSERT INTO statement comes back with key violation errors.
The three varibles in the second statement are all primary keys for that
table. They are the only primary keys for that table. I'm trying to add the
same number of questions to the table as exists in the open subform
[sfrmAuditQuestionResults].

Example: If there are 5 questions displayed on the form, I want to add
questions 1 through 5 to the table

Private Sub cmdAuditComplete_Click()
Dim mySQL As String
Dim X As Integer
Dim N As Integer
Dim NewAudit As Integer

'Add the next Audit at the next Due Date (NewDate = DueDate+Frequency)
mySQL = "INSERT INTO tblAuditsScheduled([AuditID],[DueDate])VALUES(forms!
[frmScheduledauditResults]![AuditID],forms![frmScheduledauditResults]!
[NewDate])"
DoCmd.RunSQL mySQL

'Add corresponding Audit questions to newly schedule audit
X = Forms![sfrmAuditQuestionResults]!Max([QuestionNumber]).Value

NewAudit = Forms![frmScheduledauditResults]![AuditNumber] + 1

For N = 1 To X
mySQL = "INSERT INTO tblAuditQuestionResults([AuditID],[AuditNumber],
[QuestionNumber])VALUES(forms![frmScheduledauditResults]![AuditID],NewAudit,
N)"
DoCmd.RunSQL mySQL
Next N

End Sub

--
Message posted via http://www.accessmonster.com

"Douglas J. Ste
NewsGroup User
Re: Updating a table from a form and subform11/10/2009 6:16:54 PM
Reply

0

When you run a query, Jet has no idea about VBA variables. You need to put
the value in the string, not the name of the variable:

mySQL = "INSERT INTO tblAuditQuestionResults([AuditID],[AuditNumber],
[QuestionNumber])VALUES(forms![frmScheduledauditResults]![AuditID]," &
NewAudit & "," & N& ")"


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"al416 via AccessMonster.com" <u48770@uwe> wrote in message
news:9eea4d0d7e682@uwe...
>I started this thread in FormsProgramming, but got no response.
>
> Maybe somebody in VBA can help me out
> Thanks.
>
> Any help would be appreciated:
>
> I'm trying to add lines to two different tables in two steps. One line to
> the
> first table and multiple lines to the second. The number of lines equals
> the
> same quantity of lines showing in the subform. Step one works fine (first
> INSERT INTO stement).
>
> The second doesn't work:
> 1. The X = ... statement fails. Syntax error?
> 2. The INSERT INTO statement comes back with key violation errors.
> The three varibles in the second statement are all primary keys for that
> table. They are the only primary keys for that table. I'm trying to add
> the
> same number of questions to the table as exists in the open subform
> [sfrmAuditQuestionResults].
>
> Example: If there are 5 questions displayed on the form, I want to add
> questions 1 through 5 to the table
>
> Private Sub cmdAuditComplete_Click()
> Dim mySQL As String
> Dim X As Integer
> Dim N As Integer
> Dim NewAudit As Integer
>
> 'Add the next Audit at the next Due Date (NewDate = DueDate+Frequency)
> mySQL = "INSERT INTO tblAuditsScheduled([AuditID],[DueDate])VALUES(forms!
> [frmScheduledauditResults]![AuditID],forms![frmScheduledauditResults]!
> [NewDate])"
> DoCmd.RunSQL mySQL
>
> 'Add corresponding Audit questions to newly schedule audit
> X = Forms![sfrmAuditQuestionResults]!Max([QuestionNumber]).Value
>
> NewAudit = Forms![frmScheduledauditResults]![AuditNumber] + 1
>
> For N = 1 To X
> mySQL = "INSERT INTO tblAuditQuestionResults([AuditID],[AuditNumber],
> [QuestionNumber])VALUES(forms![frmScheduledauditResults]![AuditID],NewAudit,
> N)"
> DoCmd.RunSQL mySQL
> Next N
>
> End Sub
>
> --
> Message posted via http://www.accessmonster.com
>


2 Items, 1 Pages 1 |< << Go >> >|







Similar:

numpty combo box questions

how does the tax field work in the transaction template

export query question

tables

how to add calculated field to forms

fit to screen

can i run code automatically between each field being selected ?

help

product key registration. did not receive

which is better: one or several requeries?

create a search box on a form

trying to average a parameter for each month of each year

moving label only and not box associated with it

query for record count - all tables

runcommand accmdimport

can i filter a subform combo from a textbox value on form

please help: display results in footer section of a split form

first names

updating information

how do i resize a jpg so that it fits in a msflexgrid cell?

please help me with a report

how do i find the id of the last record of a table?

change a text or combo box under prog control

is access capable of building a cost calculator?

tables

creating new list from two lists with specific data from both

pass infomration from a form to a report...

oops! didn't check "save password" when linking tables. what now?

automate access table actions based on filesystem resources?

how we create telephone directory in access 2007 with sorting ?

networking and office 2007

one listbox works but the others don't

change delimiter in access functions

contacts already in use by another person?

pivot table

closing a bound form without saving to the underlying table?

export query result from access 2003 to specific cells in excel 2007

fill fields automatically on form

how would i remove all data from northwinds template.

unable to enter data in access 2007 database on network

how do i turn on my cookies on a imac so i can get my gmail.

help with count function

default values in report

linking 3 tables with common data

displaying zeros (0) in contact information

the best way to search for a specific record id?

linked tables "read only"?

howdoiregisteronlineforwindows7

design suggestions

29 hosting web www.ivys.es

   
  Privacy | Contact Us
All Times Are GMT