Modules & VBA :: Calendar Entries - Opening Recordset Based Off Of SQL String

Oct 30, 2014

I am currently developing a calendar and am trying to open a recordset based off of a SQL string. When I deleted the Where part of the SQL statement, the code ran fine. So I am pretty sure that the problem lies within the Where part of the code. I use this code to filter my query based on txtTaskTypeID but if the value is null then the query is suppose to return all values. I keep getting Run-time error"3061: Too few parameters. Expected 1".

Code:
strSQL = "SELECT tbl1CalendarEntries.ID, tbl1CalendarEntries.Title, tbl1CalendarEntries.StartDate, tbl1CalendarEntries.StartTime, " _
& "tbl1CalendarEntries.EndDate, tbl1CalendarEntries.EndTime, tbl1CalendarEntries.TaskTypeID " _
& "FROM tbl1CalendarEntries " _
& "WHERE (((tbl1CalendarEntries.TaskTypeID)" _
& " Like IIf(IsNull([forms]![frmProductionPlanning]![txtTaskTypeID])=True,""*"",[forms]![frmProductionPlanning]![txtTaskTypeID]))) "
& "ORDER BY tbl1CalendarEntries.Title;"

View Replies


ADVERTISEMENT

Modules & VBA :: Opening A Recordset Based Upon A Variable?

Jul 5, 2013

Simple example is I have say 3 recordsets open (they are opened once as they are refered to many times) - they are open early in the form (in this example 3 price lists that are applicable for a customer) (if the syntax of the select is slightly wrong I'm just showing to 'prove' the concept).

Dim db As Database
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim rs3 As Recordset
Set db = CurrentDb()
Set rs1 = db.OpenRecordset("SELECT * FROM Prices WHERE (((Prices.ID)=1));")
Set rs2 = db.OpenRecordset("SELECT * FROM Prices WHERE (((Prices.ID)=2));")
Set rs3 = db.OpenRecordset("SELECT * FROM Prices WHERE (((Prices.ID)=3));")

What I want to do is have a central function that I can pass a list I wish to process/do something with aka. The 3 recordsets are the same except for the where criteria.

private sub GETPRICEFROMLIST(pricelist as long)

dim rs as recordset

set rs = Recordset("rs" & pricelist)
.....

I put the above to show what I'm trying to do but of course that doesn't work There won't be any updates to these recordsets only reading of data.

View 6 Replies View Related

Modules & VBA :: Add A String On Top Of The Calendar?

May 19, 2015

I have set calendar control 12.0 up and everything works how I want it to (click date and peoples names in a table to the left to show scheduled meetings on that day). What I want is to add a string on top of the calendar. For example, this monday I would like for it to say "Memorial Day" on the physical calendar itself.

View 3 Replies View Related

Modules & VBA :: Opening ADODB Recordset

Jul 2, 2013

I'm building a lab environment into one of my projects. I'm testing the distribution of values over a largish number of attempts to create a unique value.I have a table called LAB_UniqueIDTest, with two fields:

LAB_ID - the string value being tested, and
LAB_UsageCount - the number of times the value has been created.

I'm trying to open the table using the following code:

Code:

' Initialize access to the LAB_UniqueIDTest table
Set rs = New ADODB.Recordset
rs.Open "LAB_UniqueIDTest", _
CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic

I have similar snippets of code all over the application - either with a literal (as here) or as a string parameter.I do not, ever, use the options parameter of rs.open.I get error message "Run time error -2147217900 (80040e14) Invalid SQL statement - expected DELETE, INSERT, PROCEDURE, SELECT or UPDATE

My guess is it's because somehow the Open procedure is trying to interpret the tablename as a SQL statement. But how come it isn't this obtuse at other times?

View 6 Replies View Related

Modules & VBA :: String And Date - Data Type Mismatched In Recordset Filter

Jan 10, 2015

I am trying to filter a recordset with a variable q. The field in the table associated with the record set is of data type Date/time. I assigned data types String and Date to q but both cases generates the error message " Data type mismatched in expression".

View 10 Replies View Related

Modules & VBA :: Update Recordset Based On User Input Box

Oct 13, 2014

I have a form in my front end database that is supposed to allow a user to search for a record based on account number and then make changes to the that record and for it to save in the back end database. I have the search function working where it populates different input boxes on the form with what is stored in the back end database but I cannot get the update function to work. I have tried to assign each input box with a variable and then run an Update SQL function to update each of the fields but the updates are not storing. Any example of a successful update statement that uses VBA variables in it or a way to update a specific record via a recordset type function?

View 8 Replies View Related

Modules & VBA :: Formula Based On Record Number - Recordset Required?

Dec 14, 2014

In order to arrive at the required solution I have to perform a calculation, using data from each successive table record (in chronological order). The result of each calculation must then be used to arrive at the result for the next calculation.

In other words I have to update a variable based on data from each record, sorted in chronological order, and use the final result to populate a field on a form.

Is it time to break out my copy of "VBA For Dummies" and start learning how to use Recordsets?

View 8 Replies View Related

Modules & VBA :: Update Recordset Based On Max Process Instance From Another Table

Jun 7, 2013

I am trying to update a recordset using VBA based on the max "process instance" from another table. After the code executes, the field I am updating is still blank.

Code:
Set rs = db.OpenRecordset("myTable", dbOpenDynaset)
If Not (rs.BOF And rs.EOF) Then
rs.MoveFirst
Do Until rs.EOF = True
emplid = rs![Employee Number]

[Code] ....

View 5 Replies View Related

Modules & VBA :: Check If Record Already Exists In Recordset Based On 2 Conditions

May 27, 2014

I have a table in Access that I have a form saving new records to. Before this save occurs, I would like Access to check if the account number already exists and if the account does exist if it is outstanding. If both of those conditions are met I would like a message box to display and cancel the save as it is a duplicate. I can't seem to get it to work though.

I was thinking to use a filtered recordset based on one of the conditions and then perform a find on that recordset to see if it is null.

Code:

dim acct as long
dim rstfiltered as DAO.Recordset
Set rstfiltered = CurrentDb.OpenRecordset("SELECT * FROM tblclstrack WHERE [Request Status] <> 'Completed'")
acct = Me.cd_number.Value

[code]...

View 9 Replies View Related

Have A Calendar Display Entries

Jul 1, 2005

I would like to create a calendar that shows when booking entries have been made on the calendar.

Can this be done, if so how, has anyone got any examples?? Many Thanks

View 1 Replies View Related

Modules & VBA :: SQL Query Field Based On A String From Input Box

Sep 10, 2013

How do I use a update sql query to update a field based on a string from an input box. Heres what i have been trying:

Code:

Dim NETWORKBOX As String
NETWORKBOX = InputBox("NETWORK TO IMPORT" & Chr(10) & "EXAMPLE: PRIMARY", "NETOWRK TYPE")
sql = "UPDATE " & TABLENAME & " SET NETWORK = " & NETWORKBOX & " ;"
DoCmd.RunSQL sql

If i run the code and input 'PRIMARY' in the NETWORKBOX the sql query will return an 'enter parameter value dialog box' with the word 'PRIMARY' above the input field.

View 1 Replies View Related

Modules & VBA :: Insert CR / LF In Memo Field Based On Search String

Jan 16, 2014

I import a CSV field which has not preserved the CR/LF when it was exported from BCM Remedy. There is no setting for that. The memo field prints on my report like this:

A custom solution would be developed, that once implemented, could become the standard product in similar situation. Normally would assign to Network Engineering, but will work with Ray and the IPT Team to cost out the solution and get approval to proceed. 2012/05/24 10:44:28 AM PCOLLINS Sent to Ray Massie for review to determine if a solution needs to be proposed, or if they can wait for the National IPT solution to be ready in 2013.

I want to add VBA code that inserts a CR/LF in the memo field before all but the first occurance of a string that looks like a date, the first occurance doesn't need it. I will do it right after I import the CSV file into the table, so it happens only once, and it always prints and displays the CR/LF.

The memo field is called "NBS Update" and the table is called "CCRR Remedy Data"Here is what I have, but don't actually know what to put in to find the date and add a CR/LF:

Code:
Dim db As DAO.Database

Code:
Dim db As DAO.Recordset
Dim srtSQL As String

[code]...

View 14 Replies View Related

Modules & VBA :: Opening Forms Based On Results Of Union All

Apr 13, 2015

I have some code in my database that will open a form based on the result of , I think, a union query.

Private Sub resultbox_DblClick(Cancel As Integer)

'Open report based on the ID from resultbox listbox

DoCmd.OpenReport "ResultsStan", acViewReport, , "[ID] = " & Me.resultbox, , acDialog
'End If
End sub

What I need to do is open one of a number of reports. The report that needs to be opened depends on another value that is passed from the union query - DOCCAT

Being still a bit of a novice I tried...

'If "[DOCCAT]= " & Me.resultbox Like "Standards" Then
DoCmd.OpenReport "ResultsStan", acViewReport, , "[ID] = " & Me.resultbox, , acDialog
'End If

Needless to say it didn't work.

View 6 Replies View Related

Modules & VBA :: Opening File Based On Directory Location

Feb 15, 2015

When creating an incoming inspection database, I want to set it up so when I am in a form to add data, I want to have a command button where I can pull up the associated CAD drawing based on part number and drawing number. I would like to enter the directory location into a table so I could change it if I need to.

So basically I want to go something like this:

.tblDirctoryLocation
txtDirectory

.tblProduct
txtProductName
txtProductNumber
txtProductCADNo

These tables would not be related to one another as there will only be one record for the directory location and multiple records for products.

Somehow I want the db to assemble file location like this:

“EQuality_DirectoryIncoming” & “ProductNumber_” & “CADDrawing” & “.pdf”
End result: EQuality_DirectoryIncomingProductNumber_CADDraw ing.pdf

Is there any way this could be done?

View 1 Replies View Related

Getting Double Entries Using Recordset (AfterUpdate)

Jul 30, 2007

I'm stumped....(newbie):)

I"ve got a unbound combo box (customername) that has two events (on click); AfterUpdate and NotInList.

The AfterUpdate uses a 'me.recordsetclone' in order to display other data in controls associated with customerid/customername from the Customer table.

The NotInlist, does just that, adds a new customer name to the
list along with a new autonumber (used as customerid).

The problem is that I'm getting two entries (different autonumbers). I can't figure out what I'm doing wrong. If I remove the 'AfterUpdate' event, then I can't bring up the customer's data, since then there's no connection to the customername/customerid.

If I remove the Not in List, then there's no way to add a new customer. I reconfigured NotInList many many times and still I get 2 entries. One entry has Customer 'name only', The second entry has name, address, city and the rest of the fields as entered.

I tried setting an index (on Customer table) with CustID and CustomerID, making them unique, but still I'm getting 2 entries whenever I use the 'NotInList'..........Help Help,,

Here are these events:

Code: ( text )
Private Sub customername_AfterUpdate()
Dim rst As Object

Set rst = Me.RecordsetClone

rst.FindFirst "CustomerID=" & Me![customername]
If Not rst.NoMatch Then

Me.Bookmark = rst.Bookmark
Else
'Not found!
End If
Forms![Add or Delete Customer]![customername].Requery
End Sub



Code: ( text )
Private Sub customername_NotInList(NewData As String, Response As Integer)
Dim strSQL
Dim FirstName As String
Dim LastName As String
Dim SpacePosition As Integer
Dim lngNextID As Long

' Find the highest Cust ID in the Customers table and add 1
lngNextID = DMax("[CustID]", "Customers") + 1
custID = lngNextID

SpacePosition = InStr(NewData, " ")
If SpacePosition = 0 Then
MsgBox "Your entry requires a space to separate First and Last name." & _
vbNewLine & vbNewLine & _
"Please enter a First and Last Name or choose an entry from the list.", _
vbInformation, "Invalid Data !"
Response = acDataErrContinue
Exit Sub
End If

' Trim the data into first and last name using the space position.
FirstName = Trim(Left(NewData, SpacePosition - 1))
LastName = Trim(Mid(NewData, SpacePosition + 1))

If FirstName = "" Then
MsgBox "You have not entered details for the first name" & vbNewLine & vbNewLine & _
"Please fix entry.", vbInformation, "Invalid Data !"
Response = acDataErrContinue
Exit Sub
End If

If LastName = "" Then
MsgBox "You have not entered details for the last name" & vbNewLine & vbNewLine & _
"Please fix entry.", vbInformation, "Invalid Data !"
Response = acDataErrContinue
Exit Sub
End If

MsgBox "An account for this person does not exist....." & vbNewLine & vbNewLine & _
"Now creating new Customer Account.", vbInformation, "Unknown Customer Details....."
strSQL = "Insert Into Customers ([custID], [FirstName], [LastName]) " & _
"values ('" & custID & "','" & FirstName & "','" & LastName & "');"
'MsgBox strsql
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded

End Sub

Is there anyone that can help....thanks Shasha

View 6 Replies View Related

Help Opening A Recordset

Jun 30, 2005

When attempting to open a recordset, I get "Run-time error '3709': The connection cannot be used to perform this operation. It is either closed or invalid in this context."

Any suggestions would be greatly appreciated.


Public Function GetTickets(ID, NbrTickets)

Dim rsTicket As ADODB.Recordset
Dim rstAPs As Object
Dim strQry As String

Dim cnnDB As ADODB.Connection
Set cnnDB = CurrentProject.Connection

'Determine how many tickets have already been assigned...
strQry = "SELECT count([ticket number]) as nbr FROM Tickets " _
& "WHERE [Tickets]![MailList ID] = " & ID & ";"

MsgBox (strQry)

Set rsTicket = New ADODB.Recordset
rsTicket.Open strQry


With rstTicket
.MoveFirst
AssignedTiks = rstTicket!nbr 'This is the query result
End With

MsgBox ("Number of assigned tickets is " & AssignedTiks)

If AssignedTiks = NbrTickets Then
'nothing
MsgBox ("Nothing")
Else
If AssignedTiks > NbrTickets Then
MsgBox ("Remove Tickets")
'Remove Tickets
Else
'Add Tickets
MsgBox ("Add Tickets")
End If
End If

End Function

View 1 Replies View Related

Help With Opening ADO Recordset

Jun 14, 2007

I am using the following code to create a ADO recordset. The table in which the SQL refers to is in a front end database where the table is linked to the backend. I have just recently experimenting with ADO and need some help. The following code give me and error "Method 'Open' of '_object' failed. Is there a different way to crate a ADO recordset when the table is located in the backend. Please help

Private Sub Form_Load()
Dim mysql As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim PersonnelInfo As String


mysql = "SELECT tbl_Personnel.last, tbl_Personnel.RANK, tbl_Personnel.SECTION " & _
"FROM tbl_Personnel " & _
"WHERE (((tbl_Personnel.RANK)='lt') AND ((tbl_Personnel.SECTION)=[Forms]![sos Personnel]![SchShiftFind]));"


Set rs = New ADODB.Recordset
Set conn = CurrentProject.Connection

rs.Open mysql, conn, adOpenKeyset, adLockOptimistic

PersonnelInfo = rs("last")
Me.Lt1 = PersonnelInfo
End Sub

View 3 Replies View Related

Querynot Working When Opening Into A Recordset

Nov 1, 2006

Hello all,

I have a a form which I use to populate query parameters and send the result to MS Word, where a table is created from the query. The form contains 2 controls: 1) a combo box containing the month number and 2) a text box containing a year value. The form also contains a command button that opens the query into a recordset and then creates the Word table.

The query (qryCostData) contains 2 fields that reference these form parameters. The query works when:

I open the query directly (query window) while the form is open w/ the month and year parameters selected
I open the query directly (query window) when the form is closed but the month and year parameters are hard-coded into the query
I open the query using the command button on the form when the month and year paramters are hard-coded into the query


The query does not work when I open the query using the command button on the form and the query containes references to the month and year parameters from the form. The following error is returned on the following command:

command: rst.open "qryCostData", CurrentProject.Connection

error:

Run-time error: -2147217900 (8004e14)

Invalid SQL statement; expected DELETE, INSERT, PROCEDURE, SELECT, or UPDATE


Any ideas on why it works using the form command button when the parameters are hard-coded but not when referencing the form fields? If I open the form and select the parameters and then open the query through the query window, it works fine.

Thanks in advance.

Ken

View 2 Replies View Related

Opening A Report With Recordset Data

Nov 3, 2004

I have looked through the threads and have not found an answer to my question, so I post it hoping there is an answer as well as documenting useful information for other individuals.

The following code is what I am using to 'pull' data in order to print a certificate. It functions the way I designed it (verified by debug.prints and msgboxes). My question is how do I pass data to a defined report (certificate) based upon the results of a built recordset. When the report opens, the values come up as "#Name?". I'm guessing that the issue is syntax, but I just don't know. Here is the code I have so far (I've even commented it for y'all)...

Looking forward to your comments...

-BT.

Dim RSAgg As Recordset
Dim RSsrc As Recordset
Dim DB As Database
Dim strAgg As String
Dim strSQL As String
Dim strCert As String

'If there is no week number set, drop out
If Not IsNumeric(txtWeekNum) Then
MsgBox "You Must Specify a Week Number.", vbInformation + vbOKOnly, "Required Input"
Exit Sub
End If

' tblAggDesc contains the field names
' that have scores I want to evaluate.
' If someone makes a perfect score,
' then they get a certificate. Fields are
' a1, a2, a3, b1, b2, b3, c1, c2, c3.
strAgg = "SELECT tblAggDesc.AggCourse, tblAggDesc.AggDesc FROM tblAggDesc;"

Set DB = CurrentDb()
Set RSAgg = DB.OpenRecordset(strAgg)

RSAgg.MoveFirst
Do While Not RSAgg.EOF
If (Right(RSAgg!AggCourse, 1) > 1) Then 'rounds 2 & 3 contain additional information that is printed on certificate
strSQL = "SELECT tblScores.HEDR, tblRoster.Fname, tblRoster.Lname, tblScores.WeekNo, tblScores." & RSAgg!AggCourse & ", tblScores." & RSAgg!AggCourse & "X AS AggCourseX " & _
"FROM tblRoster LEFT JOIN tblScores ON tblRoster.HEDR = tblScores.HEDR " & _
"WHERE (((tblScores.WeekNo)=" & [txtWeekNum] & ") AND ((tblScores." & RSAgg!AggCourse & ")=100));"
Else
strSQL = "SELECT tblScores.HEDR, tblRoster.Fname, tblRoster.Lname, tblScores.WeekNo, tblScores." & RSAgg!AggCourse & " " & _
"FROM tblRoster LEFT JOIN tblScores ON tblRoster.HEDR = tblScores.HEDR " & _
"WHERE (((tblScores.WeekNo)=" & [txtWeekNum] & ") AND ((tblScores." & RSAgg!AggCourse & ")=100));"
End If

Set RSsrc = DB.OpenRecordset(strSQL, dbOpenDynaset)
If Not (RSsrc.BOF And RSsrc.EOF) Then
RSsrc.MoveFirst
Do While Not RSsrc.EOF
If (Right(RSAgg!AggCourse, 1) > 1) Then
strScore = RSsrc!AggCourseX & "X"
Else
strScore = ""
End If
'MsgBox RSsrc!Fname & " " & RSsrc!Lname & " " & RSsrc!WeekNo & " " & RSAgg!AggCourse & " " & strScore & " " & RSAgg!AggDesc
strCert = "Fname='" & RSsrc!Fname & "' AND Lname='" & RSsrc!Lname & "'" & " AND WeekNo='" & RSsrc!WeekNo & "' AND XCount='" & strScore & "' AND AggDesc='" & RSAgg!AggDesc & "'"
'Debug.Print strCert

' this is the point that I have problems.
' I want to pass RSsrc!Fname,
' RSsrc!Lname, RSsrc!WeekNo,
' RSsrc!AggCourseX, RSAgg!AggDesc to
' the report.
DoCmd.OpenReport "rptCleanTarget", acViewPreview, , strCert

RSsrc.MoveNext
Loop
End If

RSsrc.Close
RSAgg.MoveNext
Loop

RSAgg.Close
Set DB = Nothing

View 6 Replies View Related

Modules & VBA :: How To Extract Recordset From Subform Into Recordset Object

Aug 14, 2015

Special situation: The SQL Server Linked Server across the country is linked to a Read Only Oracle DB. This data pull works perfectly and populates the Subform.

The problem is that Oracle can take 3 to 6 seconds to retrieve the single record depending on the network traffic through a small pipe.

The code below shows the RecordSource for the SubForm. clicking on a list box supplies the value. Then 3 to 6 seconds later, the subform populates.

The actual Recordset for this Recordsource is needed to conduct Validation on each field. Normally this would be on SQL Server, I might just create a Recordset Oject and run this SQL statement again in 1 milisecond. In this case, it will probably take an additional 3 to 6 seconds. Avoiding another lengthy round-trip to Oracle would be prefered.

Goal: How does one grab, clone, or other wise reference the existing recordset for the SubForm?

Note: Immediate Window - One single field can be returned quickly

There are 48 fields that need validation - is there a way to reference the entire recordset?

Immediate Window during Break Mode:
? me.fsubsrNavSHLBHL("NavSH_QQ")
NESE ' this is the correct value for the current recordsource

Set a breakpoint right after the line:
fsubsrNavSHLBHL.Form.RecordSource = "Select * from vsrNavigatorSHLBHL where Well_ID =" & txtNavWellID.Value

Immediate Window:
? me.fsubsrNavSHLBHL.Form.RecordSource
Select * from vsrNavigatorSHLBHL where Well_ID =91229

View 4 Replies View Related

Modules & VBA :: Test String Test Based On Table Data

Oct 31, 2013

my issue is i have multilble text box in my form & based on change in one of this text box i need the code to compare between data in the form & table & returm Msg if it is not matching. attached screen FYI.

i look in the internet but i could not figuer out the VBA code since i do not know VBA. what comes to my mind to to use select case.

View 14 Replies View Related

Modules & VBA :: Input String In Column Based On Data In Another Column?

Nov 30, 2014

I need to input a string into a column named "EventType". The code should first check if the column "Agent Name" contains any strings. If there is none, it will input "IBM Director" into the EventType column.

Once it has looped through the agent names, the code will then loop through the Details column and input into EventTypes based on what is displayed within the string.

These are the codes that I am using to achieve this, however nothing is being input into the EventType column.

Code:
Private Sub Command11_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Final")

[Code] ....

I think the problem lies with the code that checks the agent name. When I removed it, it managed to populate the EventType column based on the details. But I still need to find out how to check the agent name too.

View 4 Replies View Related

Modules & VBA :: Separate Numbers And String From Alpha-numeric String

Jun 7, 2013

MS-Access VBA code to separate numbers and string from an alphanumeric string.

Example:

Source: 598790abcdef2T
Output Required: 598790

Source: 5789065432abcdefghijklT
Output Required: 5789065432

View 13 Replies View Related

Modules & VBA :: Can Use Result Of One Recordset For Other Recordset

Jul 7, 2013

I want to write a email where there are 2 or 3 different ordernumbers for same email, i want to include the email in the mail part as single column table. how to do it? also can i use result of one recordset for other recordset?

View 1 Replies View Related

Calendar Based On Task

Dec 14, 2005

As a continuation from this thread (http://www.access-programmers.co.uk/forums/showthread.php?t=98369)...

Currently, I have a list of programs, each program could be considered the "task". When the task is completed, I want the user to click the date on the calendar and have it grayed out. As I mentioned before I have this working correctly, but I have the calendar pulling up based on a query that relys on the program ID. No problem, that way each program has it's own calendar. Now I need to be able to have it pull up the current month if one exists, and if it does not exist create it. For instance it works fine now, but once we hit 1/1/06, it will still be the same calendar... I want it to create a new record, so I could theoretically look at the old calendar if need be.

I tried to tie my query to a month field as well, but to no avail.

Thanks for your help!

View 14 Replies View Related

Auto Populate Cells Based On Three Entries

Feb 23, 2015

I would like to put a date in a form the region and then a staff code and based on the three entries then auto populate the remaining cells if those three have been entered together previously. Is this possible?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved