473,799 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Docmd.runsql

83 New Member
Hello. I have two questions:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Form_Load()
  2. Dim assID As Long
  3.    assID = DMax("CLng(Right([LSI_Case_Number],3))", "Master_Log")
  4.    Me.LSI_Case_Number = Month(Date) & Format(Year(Date), "yy") & "-" & Format(assID + 1, "000")
  5. End Sub 
  6.  
It reads an indentifier cursor error. In my table LSI_Case_Number is a text variable

Next question:
I have a form that has all the variables from my main table: Master_Log, and one of the variables is Disposition.
Disposition is automatically filled in upon hitting enter(it depends on many of the variables in the form).
If the disposition says "rejected", I would like the case to be sent to the "Rejected" table(which is just an empty copy of the Master_Log), and deleted from the Master_Log.

I think I am supposed to use Docmd.runsql, but does it matter if try to use that command in an after_update Disposition. I think it does matter, it needs to be a DoSql sub.
Here is my poor attempt:
Expand|Select|Wrap|Line Numbers
  1. Private Sub DoSql()
  2. Dim SQL As String
  3. If Me.dispostion = "Reject" Then
  4. SQL = "APPEND Rejected"
  5. End If
  6. DoCmd.RunSQL SQL
  7. End Sub
  8.  
Apr 4 '07 #1
3 2581
Rabbit
12,516 Recognized Expert Moderator MVP
Hello. I have two questions:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Form_Load()
  2. Dim assID As Long
  3.    assID = DMax("CLng(Right([LSI_Case_Number],3))", "Master_Log")
  4.    Me.LSI_Case_Number = Month(Date) & Format(Year(Date), "yy") & "-" & Format(assID + 1, "000")
  5. End Sub 
  6.  
It reads an indentifier cursor error. In my table LSI_Case_Number is a text variable

Next question:
I have a form that has all the variables from my main table: Master_Log, and one of the variables is Disposition.
Disposition is automatically filled in upon hitting enter(it depends on many of the variables in the form).
If the disposition says "rejected", I would like the case to be sent to the "Rejected" table(which is just an empty copy of the Master_Log), and deleted from the Master_Log.

I think I am supposed to use Docmd.runsql, but does it matter if try to use that command in an after_update Disposition. I think it does matter, it needs to be a DoSql sub.
Here is my poor attempt:
Expand|Select|Wrap|Line Numbers
  1. Private Sub DoSql()
  2. Dim SQL As String
  3. If Me.dispostion = "Reject" Then
  4. SQL = "APPEND Rejected"
  5. End If
  6. DoCmd.RunSQL SQL
  7. End Sub
  8.  
Well, I tested it and it works. Are you sure the last 3 characters will always be numbers?

An Append SQL is contructed like this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TableName1
  2. SELECT Fields
  3. FROM TableName2;
  4.  
Apr 4 '07 #2
jl2886
83 New Member
So what would my code look like for the append and delete look like for an after update of my dispostion variable.
The assign id works but only when i load the form. Can I do a click statement that assigns the lsi_case_number . and for some reason the year is 05.
Apr 4 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
So what would my code look like for the append and delete look like for an after update of my dispostion variable.
The assign id works but only when i load the form. Can I do a click statement that assigns the lsi_case_number . and for some reason the year is 05.
I don't know what your code would look like, I don't know anything about how table structure.

Yes, you can put the code in your on load in the on click event of a control.
Apr 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
8247
by: Jim | last post by:
I am using Access 97 on a PC running Windows NT 4.0 SP6a. I have some code (shown below) intended to add a set of records to one table (tblGradeProps) when a new record is created in another (tblGrades) The oddity is that when the procedure Detail_Click is called from the procedure cmbMktSect_Exit, the RunSQL statement doesn't add the required records but it does so when invoked by the Detail_Click event!
4
10194
by: Rotsj | last post by:
Hi, i try to execute an update query from within a form, but i get the message: run time error '3144'. Syntax error on the update statement when i try something like this: DoCmd.RunSQL "UPDATE tblKlant " & _ "SET tblKlant.Bedrag = tblKlant.Bedrag + 10.96" & _ " WHERE tblKlant. = forms!!"
0
1943
by: Andy | last post by:
Hello, I am running an sql statement that INSERTS INTO a table. If I run the query using docmd.runSQL, it works fine - new records are added to the table and duplicate records are disregared ( I use DoCmd.SetWarnings False so the users don't see the warning about duplicate records). If I run the same query using this: rs.Open qryPolePosition1, CurrentProject.Connection, adOpenKeyset,
3
3470
by: Pathfinder | last post by:
Hi All I am trying to run the below but I receive the following error "runsql action requires an argument consisting of an SQL statment" Dim MySQL$ MySQL$ = "Select * from mytablename" DoCmd.RunSQL MySQL$ Any reason for that
7
4297
by: Richard Hollenbeck | last post by:
Help! I don't know why this isn't working: Private Sub Combo9_Change() Dim UsersCourseSelection As String UsersCourseSelection = Me("Combo9").Value Combo13.Visible = True 'the following SQL thing is all on one line in the actual code.
8
11243
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to update 3 row(s)." Is there a way to prevent the message from popping up?
6
68820
by: David | last post by:
I am trying to insert an employee number into the EmpNbr field in my main table from a form where I add a new employee to my employee table. I was hoping this command would work, but it isn't. DoCmd.RunSQL "INSERT INTO VALUES ()", 0 This is the only field I want to populate in the main table from this form. there are three other fields in the main table that I want to leave unpopulated.
2
5708
by: ben | last post by:
I have the following code in a VBA module: DoCmd.RunSql "Update tData Set sd = Log(Strike/Price) where symbol = '" & symbol & "'" This statement worked fine, and was using the built in math Log function. In a separate module, I added the following function:
1
3083
by: natural | last post by:
Good Afternoon I have an option grou[ and on the after update i would like to provide the user with a msgbox, and then action placed my docmd.setwarnings false everywhere, but i still get my "record has been deleted". Is i possilbe to please assist in where i am going wrong Private Sub RecOffLet_AfterUpdate() On Error GoTo Err_Handler
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10470
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9067
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.