Solved

Parameter Value when running code

Posted on 2008-06-18
12
173 Views
Last Modified: 2013-11-28
I am asked to enter a parameter value when I run this code. Anybody know why.

Thanks
Private Sub btn_Update_Days_Worked_Click()

 

   Dim WeekNumber As Byte

   Dim DayOfWeek As Byte

   Dim WeekText(1 To 2) As String

   Dim CurrentCheckBox As CheckBox

   

   For WeekNumber = 1 To 2

      For DayOfWeek = 1 To 7

         Set CurrentCheckBox = Me("WKDay" & LeadingZero(DayOfWeek + ((WeekNumber - 1) * 7)))

         If CurrentCheckBox = 0 Then

            WeekText(WeekNumber) = WeekText(WeekNumber) & "X"

         Else

            WeekText(WeekNumber) = WeekText(WeekNumber) & GetFirstLetterOfDay(DayOfWeek)

         End If

      Next

   Next

   DoCmd.RunSQL "INSERT INTO tbl_EmployeeShiftInformation (DaysWorkedWK1, DaysWorkedWK2) VALUES ([WeekText(1)], [WeekText(2)])"

   

End Sub

Open in new window

0
Comment
Question by:life42
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 3

Expert Comment

by:BitRunner303
Comment Utility
See if this works:

DoCmd.RunSQL "INSERT INTO tbl_EmployeeShiftInformation (DaysWorkedWK1, DaysWorkedWK2) VALUES (""" & WeekText(1) & """, """ & WeekText(2) & """)"
0
 
LVL 19

Expert Comment

by:frankytee
Comment Utility
the error is this line:
 DoCmd.RunSQL "INSERT INTO tbl_EmployeeShiftInformation (DaysWorkedWK1, DaysWorkedWK2) VALUES ([WeekText(1)], [WeekText(2)])"

it should be:
 DoCmd.RunSQL "INSERT INTO tbl_EmployeeShiftInformation (DaysWorkedWK1, DaysWorkedWK2) VALUES ('" & WeekText(1) & "','" & WeekText(2) & "')"
0
 

Author Comment

by:life42
Comment Utility
I now get the following message: Microsoft Office can't append all the records in the append query.

I just want to update a single record in the table.
0
 
LVL 19

Expert Comment

by:frankytee
Comment Utility
thats because your sql statement is an insert (ie append) and not an update statement
an update statement would be something like:
DoCmd.RunSQL "update tbl_EmployeeShiftInformation set DaysWorkedWK1 ='" & WeekText(1) & ', DaysWorkedWK2 = '" & WeekText(2) & "'" & " WHERE ..... whatever record id etc"


0
 
LVL 19

Accepted Solution

by:
frankytee earned 250 total points
Comment Utility
typo, it should be (replace accordingly):
DoCmd.RunSQL "update tbl_EmployeeShiftInformation set DaysWorkedWK1 ='" & WeekText(1) & "', DaysWorkedWK2 = '" & WeekText(2) & "'" & " WHERE whateverIDfield = " & whateverid
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
you will need an update query not an insert (append) query

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:life42
Comment Utility
frankytee, I will try this, but low group question , why an update not an insert statement.

Thank you
0
 

Author Comment

by:life42
Comment Utility
What do I do if I am populating a new table with empty fields how do I write this UPDATE statement?
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
life42,

updating a field in a table means revising/editing the fields value of an existing record.

appending to a table means inserting/adding a new record to the table.


what do you want to do?
0
 

Author Comment

by:life42
Comment Utility
I want to update a table, that has employee id employee name and department already populated I want to add what days of the week they work based on checkbox values. I have the checkbox values stored, I just need to update the employee record in the table based on the input from the form.

0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
frankytee already posted the codes at http:#a21813152
0
 

Author Closing Comment

by:life42
Comment Utility
Thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Correct ordering 14 42
MS Access Query Help For Graph Preparing 13 15
SQL query 4 25
Error in SQL Query 36 33
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now