Docmd.RunSQL Upadate Problem ??
May 10, 2007
Hey guys.
I have a VBA application i am writing.
I am trying to use an sql statement with docmd.runsql to insert a value into my table that matches a particular record. (which will be the one open). For testing purposed i have stripped down my code.
When running the code it works, however it puts chinese symbols in all the other fields of the record and dose not insert the record into the CapExFileName Field. Then when you try and delete the record it comes up with no search index found.
Any idea on why it would be doing this ?
here is the code.
.......
Dim SQLstring As String
SQLstring = "UPDATE Assets SET Assets.CapExFileName = 'Test' WHERE Assets.Barcode = 'Testies1234'"
Docmd.RunSql SQLString
....
Mark.
View Replies
ADVERTISEMENT
Jul 27, 2006
I've the following SQL query in my database:
DoCmd.RunSQL "INSERT INTO tblPlanner ( RACF, [Date], [Day Capacity], [Role Title], TimeWork ) SELECT tblStaff.RACF, [txtday1] AS Expr1, tblStaff.[Daily Capability], tblStaff.[Role Title], tblStaff.[Contract mins] FROM tblStaff WHERE (((tblStaff.TeamName) Like [txtTeamName])) WITH OWNERACCESS OPTION;"
The problem is everytime it runs it informe that the query will change data in the table. What can I do to stop it?
Thanks
View 3 Replies
View Related
Jul 12, 2007
Hi guys,
what's the problem in this code:
DoCmd.RunSQL "SELECT * FROM SecounderyInfo WHERE [LangEs]=Yes;"
every time i excute it an error appear:
Run-time error '2342'
thanx
View 1 Replies
View Related
Mar 2, 2008
hello,
im creating a small database and am extremely new to vba, ive got stuck on running a select query from within the vba code itself, the book im currently reading while learning about this stuff suggests my code whould work but after looking into it i believe its wrong as ive read various threads saying you cannot use docmd.runsql with a select query, just wondering if anyone could help and throw some light on how to get this little bit of code working. below is the part of my code that falls over,
basicaly it should lookup the weight based on what the parcel type is and find the price, the parcel type is worked out earlier in my code and is held in strParcelType, theirs probably an easier way to do this as well but have'nt got that far in my book :)
intWeight = Me.txtWeight
Select Case intWeight
Case 0 To 100
intCost = DoCmd.RunSQL "SELECT pricetable1.[Postage Name], pricetable1.[0-100g] FROM pricetable1 WHERE (((pricetable1.[Postage Name]) = strParcelType))"
Case 101 To 250
intCost = DoCmd.RunSQL "SELECT pricetable1.[Postage Name], pricetable1.[101-250g] FROM pricetable1 WHERE (((pricetable1.[Postage Name]) = strParcelType))"
Case 251 To 500
intCost = DoCmd.RunSQL "SELECT pricetable1.[Postage Name], pricetable1.[251-500g] FROM pricetable1 WHERE (((pricetable1.[Postage Name]) = strParcelType))"
Case 501 To 750
intCost = DoCmd.RunSQL "SELECT pricetable1.[Postage Name], pricetable1.[501-750g] FROM pricetable1 WHERE (((pricetable1.[Postage Name]) = strParcelType))"
Case 751 To 1000
intCost = DoCmd.RunSQL "SELECT pricetable1.[Postage Name], pricetable1.[751-1000g] FROM pricetable1 WHERE (((pricetable1.[Postage Name]) = strParcelType))"
Case 1001 To 1250
intCost = DoCmd.RunSQL "SELECT pricetable1.[Postage Name], pricetable1.[1001-1250g] FROM pricetable1 WHERE (((pricetable1.[Postage Name]) = strParcelType))"
End Select
Me.txtEstimate = strParcelType & intCost
many thanks to any gurus who can point me in the right direction or show me a easier way to do this
View 11 Replies
View Related
Nov 2, 2006
After a hiatus of a few years I find myself back writing Access applications, so I need to get caught up a bit.
First of all help me out with the whole ADO, DAO RunSQL thing. In the past whenever I needed to do any database operations I almost always used straight SQL with DoCmd.RunSQL, e.g.:
lsSQL = "INSERT INTO tblUsers CenterID, WorkerID..."
DoCmd.RunSQL (lsSQL)
Most other coders seem to use some recordset approach, e.g:
Set rst = dbs.OpenRecordset("tblUsers")
rst.AddNew
rst("ClientID") = Me.ClientID.Value
rst("WorkerID") = Me.WorkerID.Value
...
rst.Update
The only time I ever used recordsets was when I needed to loop through each record and apply some logic that was too convoluted for SQL or at least too convoluted for me to write in SQL.
So, what's the advantage of using recordsets - whether ADO or DAO - over RunSQL?
View 9 Replies
View Related
Aug 24, 2006
I have a table with one entry- just a date that holds the last day of the month for a function that reminds the user to do something. I have some code that's supposed to change this entry via an update query- but it's not working- literally, no errors, just nothing. I tried running it in an actual query- but still nothing.
The query should update the table endCurrMonth to the last day of the month. I've tried hardcoding various dates- still nothing
DoCmd.RunSQL ("UPDATE tableMetrics SET tableMetrics.endCurrMonth = DateSerial(Year(Date()), Month(Date()) + 1, 0)")
anyone know what I'm doing wrong?
thanx
View 5 Replies
View Related
Sep 12, 2006
Hi trying to get my runsql to work
DoCmd.RunSQL "INSERT INTO tblLogTimer (Operator, Dato, LogOn, LogOff, LogTime, Status) VALUES ('" & StrOperator & "', '" & Datotext & "', '" & MeetTime & "', '" & LeaveTime & "', '" & LogTime & "', '" & StrMeetStatus & "')
But if keep updating all the records and I'm only interesting to get the 1 updated...so I've been trying this ....
DoCmd.RunSQL "INSERT INTO tblLogTimer (Operator, Dato, LogOn, LogOff, LogTime, Status) VALUES ('" & StrOperator & "', '" & Datotext & "', '" & MeetTime & "', '" & LeaveTime & "', '" & LogTime & "', '" & StrMeetStatus & "') WHERE Operator=me.txtLogOperator"""
but the access keep telling that I'm needing a ";" but where should I put it???
View 1 Replies
View Related
Oct 1, 2007
Can someone please tell me where I went wrong with the following:
SQL = "UPDATE tblSoldCase " & _
"SET tblSoldCase.[Case Name] = tblProspect.[Case Name], tblSoldCase.[Admin Letter App/Decl] = tblProspect.[Admin Leffer App/Decl]" & _
"Where (((tblProspects.[Case Track Nbr]) = " & Me.txtCaseTrackNbr & "));"
DoCmd RunSQL SQL
I want run a update SQL
View 5 Replies
View Related
Jul 13, 2006
have this code on a on click event of a button on a form
Code:lngMyEmpID = Me.cboEmployee.value yes = "Yes" DoCmd.RunSQL ("UPDATE Users " & _ "SET [loggedIn] = '" & yes & "' " & _ "WHERE [lngEmpID] = lngMyEmpID;")
it prompts the user to enter the value for lngMyEmpID,
i have tried to change the WHERE to
"WHERE [lngEmpID] = '" & lngMyEmpID & "'
buth then get a data type mis match error
the lngEmpID is the column name of the table and its an autonumber
the lngMyEmpID is a number tied to a combo in which the user selects the username.
any ideas on how to get this working
View 1 Replies
View Related
May 18, 2005
can some one help.
i have two tables table1,table2 each with one same field Country.
In my RunSQl query, i want to delete all records in table1 and table2 simultaneously from one button with a certain country.
The problem is how can i do this from may be one RunSQL statement
i tried to use two deletion runSQl commands, but only one is executed. Actually the one that comes second.
If i put doevents in the middle of these statements, only the first is executed.
Here is my code:
Private Sub RemoveCtry_Click()
docmd.setwarnings false
Docmd.RunSQL "DELETE * FROM table1 WHERE (Country='" & USA & "')"
Doevents
Docmd.RunSQL "DELETE * FROM table2 WHERE (Country='" & USA & "')"
docmd.setwarnings true
End Sub
if I use One Statement:
Docmd.RunSQL "DELETE table1.Country,table2.Country FROM table1,table2 WHERE ((table1.Country='" & USA & "' ) AND (table2.Country=' " & USA & " '))"
I get an error that i have to specify the table to delete from!!!!
View 14 Replies
View Related
Sep 7, 2006
have searched on above but could not find anything
I want to start another database from within a database from a command button
Use the wizard option for RunApp and it appeared to work okay. definately pointing at the database.
Event procedure is
Private Sub Command39_Click()
On Error GoTo Err_Command39_Click
Dim stAppName As String
stAppName = "msaccess.exe C:LenWorking DatabaseSingle Non Conformance SystemDatabaseSecure Defect Docket Database.mdb"
Call Shell(stAppName, 1)
Exit_Command39_Click:
Exit Sub
Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click
End Sub
Getting error saying that I was trying to use an option in command line that was not recognised.
Few clicks on the OK and the error message cannot find file
Any clues please
len
View 6 Replies
View Related
Feb 1, 2005
I have aproblem with the range of this thing. I think I have a wrong synthax or something.
I need to have the first 120 records of columns A and D
The first two lines aren't records but titles
So I had:
DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel8, "ExcelTEMP", mijnFile, False, "A3:A122;D3:D122"
Access tels me there is somthing wrong with the range, though it works in Excel :confused:
View 3 Replies
View Related
Oct 29, 2004
I am trying to develop a page where users can click on alphabets to look for a company name that starts with the selected letter.
Searching through the forums i came across the method of using DoCmd.
alpha = Request.QueryString("alp")
if alpha <> "" then
DoCmd.ApplyFilter "", "[com_name] Like ""[" & alpha & "]*"""
end if
The 'alpha' variable here holds the alphabet selected by user from another page. However, I'm getting an error message saying
Microsoft VBScript runtime (0x800A01F4)
Variable is undefined: 'DoCmd'
Initially i tried the usual filtering
if alpha <> "" then
rs.Filter = "com_name LIKE " & alpha
end if
The pages are suppose to display records in 10s. But instead of showing only the records of company starting "A" (example) it shows everything.
Please kindly point me to the correct direction to solve this problem.
Thank you so much.
-meiyeen-
View 2 Replies
View Related
Apr 27, 2006
Hello,
I have tried using the following code to maximize my form on open but it is not working, any ideas?
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
DoCmd.Maximize
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open
End Sub
View 2 Replies
View Related
Apr 8, 2008
Can someone tell me the difference between 'Call' and 'DoCmd' and how each are executed. For my level of programming, an newbie at that, I've used it interchangably so far without a problem. But I'm beginning to think that there is a difference. I don't want to later have to go back to redo my code down the line. I'm beginning to think that I've been very lucky so far in being able to use it interchangebly and my luck will run out soon.:eek:
View 7 Replies
View Related
Mar 5, 2007
I need to execute an append query from my vba code but I have to pass in a parameter. I can't set the parameter equal to a form control. I have to actually pass in a value. I don't want to use a querydef because I don't have any result sets.
Any help would be great.
Thanks
View 1 Replies
View Related
Jan 24, 2005
Hi,
I have got an unbound access form, and in this form I gather 2 dates (i.e. through txt fields). Once I have these fields, I want to open a form that has one list box on it. This list box should populate based on the dates that I gather on the previous form. How do I specify this through the DoCmd.OpenForm arguments? Currently I have the following code, but it is not working:
Form 1:
Dim whereClause As String
whereClause = "SELECT * FROM qryInvoice WHERE tblInv.InvDate Between #" & txtStartDate & "# And #" & txtEndDate & "#" & ";"
DoCmd.OpenForm "frmInvoiceFax", acNormal, , , , , whereClause
Form 2:
public Sub Form_Load(args As String)
MsgBox args
lstInvoice.Rowsource = whereClause
End Sub
I know I am not doing it the right way (because it is not working), but I can't actually find how to do it. Help!
View 2 Replies
View Related
Mar 18, 2005
I have a form(frmGetRecord) with a subform(frmSubGetRecord). frmGetRecord has a combobox cmbCNO to choose the patient. The subform displays the admit date and discharge date(if there is one). There can be multiple admit/Discharge dates for a patient. Based on the values from fields on the form and subform, I would like to open a data entry form(frmEvents) for the particular record. I have a command button to run the code to open frmEvents. I am having trouble with the criteria in the where condition.
stLinkCriteria = "[CNo]=" & "'" & Me![cmbCNO] & "'" _
And "[AdmitDate]=" & "#" & Forms![frmGetRecord]![frmSubGetRecord].Form![AdmitDate] & "#" _
And "[DischDate]=" & "#" & Forms![frmGetRecord]![frmSubGetRecord].Form![DischDate] & "#"
DoCmd.OpenForm stDocName, , stQryName, stLinkCriteria, acFormEdit
When I click on the command button I get a type mismatch error. If I test the StLinkCriteria separately, the DoCmd.OpenForm will work for just the CNO field or just the AdmitDate field. If I test those two strings together, I get the type mismatch. Also, DischDate could be blank and I'm not sure how to add an IIf statement to the string to test for that in the where statement. I'm also not sure how to make sure it picks the correct record if there is more than one admit date. I would like to select the desired date record, then have the command button open the appropriate record.
Hope this makes sense. Thanks for any help.
View 10 Replies
View Related
Jul 6, 2005
Here is a strange problem I had never encountered before.
I have a form with a few command buttons. One button runs a Docmd.RunSQL code which append some records to a table. Another button runs a Docmd.RunSQL code that delete some records from the same table. The table is a simple table with only 5 fields.
The problem is after I opened the form I can only use one of the above buttons ONCE, after that I got this error message on all codes that began with Docmd.:
Run-time error '2486':
You can't carry out this action at the present time.
AND
I could not close the form. I could only close the databse file but could not exit MsAccess. I had to use Task Manager to end MsAccess process.
I had searched several forums but could not find any clue. Hope that I don't have to do the form from scratch again. Thanks for any help.
Peter :confused:
View 1 Replies
View Related
Jul 28, 2005
I have a group form with extra buttons to print, review a report or close the form.
If I use a Macro then I can close the form.
I converted the macro to code and I get the error message:
A problem occured while Microsoft Access was communicating with the OLE server or ActiveX Control
*The expression may not result in the name of macro, ...........
*There may have been an error evaluating........
What am I doing wrong :confused:
Cheers
Gordon
View 6 Replies
View Related
Oct 27, 2005
Hi there
I am making a form that has been set up to have a number of tabs so I can have more then 1 page on the form.
One of the tab pages is used as a search form.There is a couple of textboxes and a listbox where the results end up
What I am trying to do is have a double click set up on the listbox so I can double click the result I want and have the forms ID goto that record.
Its a bound form. The primary key is called PersonalID and its bound to a txtbox called txtPersonalID.
this is my code but its not working
Private Sub lstSearchResults_DblClick(Cancel As Integer)
Dim strPersonalID As String
strPersonalID = Me.lstSearchResults.Column(0)
DoCmd.GoToRecord acActiveDataObject, "PersonalID", acGoTo, strPersonalID
DoCmd.GoToControl "pgePersonalInformation"
End Sub
When I try run the code I get an error 2489. saying The object 'PersonalID' isn't open.
What am I doing wrong?
Can anyone help out
TIA
View 2 Replies
View Related
Mar 23, 2006
Hi all,
To export a file to MS excel from my form, i used the command
DoCmd.OutputTo acOutputQuery, langName & partName, acFormatXLS, exportPath, False
however, i realised that the format of the excel spreadsheet (excel version 5.0/95) that i have exported is slightly different from the format of the spreadsheet if i had exported by clikcing on FILE, EXPORT...
how can i specify the excel version for the exported file? i wan it to be in the latest excel version else i am unable to perform some of the marcos i have written in the latest excel format?
Thks FT
View 2 Replies
View Related
Aug 15, 2006
i have a listbox that manipulates records on another form but in case i click on one of the records in the listbox that doesnt have any corresponding record in the other form then instead of it saying that it cant locate the record i would like the form to go to a new record....
i've been trying at it but cant get it right...
plz assist... anyone.
View 14 Replies
View Related
Jan 26, 2005
I am trying to find a way to use the "DoCmd.SendObject acReport" feature WITHOUT using Outlook. Does anybody know of any code or a setting that will enable me to specify another e-mail program, such a Thunderbird?
I should add that I am using Access 2002, SP3, running in Windows XP Professional, Version 2002, Service Pack 2.
Thanks
rkc
View 1 Replies
View Related
Sep 1, 2006
I have this code for email function from form of DB
Private Sub Email_Click()
On Error GoTo Err_mail_Click
Dim stDocName As String
stDocName = "TRANSMITTALGEN"
DoCmd.SendObject acSendReport, stDocName, acFormatSNP, Me.ClientEmailID, Me.UMLEmailID, , Me.Subject, Me.Message
Exit_mail_Click:
Exit Sub
Err_mail_Click:
MsgBox Err.Description
Resume Exit_mail_Click
End Sub
As can be seen there is one report which gets attached to email message. But here I want to have one condition, means if
[Forms]![frmLogon]![Project]="P-159" then this attachment is ok else [Forms]![frmLogon]![Project]="P-172" then it should change stDocName to another report.
Any help plz.
View 1 Replies
View Related
Oct 27, 2007
Hi to all you database wizards I have a problem, it is as follows
I have just put a command control onto a form and this is what happens. I type
Docmd
to this point all is ok. now when I put the .(dot) after Docmd
Docmd.
it changes to
Docmd.
the drop down box opens for about 1 sec then closes and I now have Docmd. in a red color and with no drop down box with the listed objects
Anything that I type just comes out red until the code line is finished, then it reverts back to black print and blue on the objects words
your help will be appreciated
Jabez
View 2 Replies
View Related