access-vba

Table with selectable items in Access 2003

I need to create a form in which user can select one item from the table. Then user can click on button so data in selected row can be used in next step. I am unable to find optimal solution. First, I don't know how to make such view/table with selectable items. Second, I don't know how to gather data from selected row. I am totally new...

vba: do something if it is midnight

i will need to run a process once every 24 hours at midnight. it wont matter if it's 12:00:00 or 12:00:03, just as long as it is run once at around midnight. would i need to have a timer control checking what time it is every minute or is there a more sophisticated/simpler way of doing this? what would be the if statement to check whet...

VBA help with executing procedure

Private Sub CmdPharmacy_Click() Dim myM(11) As String Set mydb = CurrentDb If PMNM = "" Then PMNM = UCase(Left(cboMonth.Value, 3)) End If sQ = "SELECT mN FROM PharDate WHERE mT = '" & PMNM & "';" Set myrec = mydb.OpenRecordset(sQ, dbOpenDynaset) myrec.MoveFirst myC = myrec.Fields("mN") For i = 0 To myC - 1 myM(i) = "M" & i +...

How to wait for execution control to return from dropping a table?

I have the following code: CurrentDb.Execute "DROP TABLE [" & DatabaseName & "].[" & TableName & "];" Which will drop a table from an MS Access database. Typically this is being done using a database on a shared network. How can I ensure the DROP method completes before allowing the control to move on to the next line in my code? T...

MS-Access: How to open form in same location/size as closed/previous form?

I am creating a database application using Access 2003 that will be run as a stand-alone application (i.e. using the Access runtime). I have a main form that opens to a pre-defined location and size and I would like to control where any other forms open. I would like to open additional forms at the same location and size as the main for...

Set rs = nothing : usefull before closing form ?

In Access, always supposed that in Forms modules, as in other (class or regular) modules, objects and normal variables cease to exist when the code is exited, or in the case of Forms, when the form is closed. Is that correct ? I am wondering because I built a form used to scan barcodes on orders, and it gets slower and slower during ...

error 3075 when running SQL in access 2007 vba

I wonder why I can't execute this SQL query in access 2007 through VBA, which can be executed when i create a query myself: Private Sub SQL_Click() Dim curDatabase As Database Dim RS_REPORT As Recordset Set curDatabase = CurrentDb Set RS_REPORT = _ curDatabase.OpenRecordset("REPORT_CONTENT_ARCHIVE", dbOpenDynaset) strStatement = "SEL...

I'm getting an Error "runtime error 2105 access you can't go to the specified record"? please help me

Private Sub cmd_New_Click() Dim Response% If Me.Dirty Then Response = MsgBox("Save changes to the job record?", vbYesNoCancel, scAppTitle) Select Case Response Case vbYes SendKeys "+{Enter}" Case vbNo Me.Undo Case vbCancel Exit Sub End Select ...

running regsvr using VBA

Hi guys Is there a way I can run regsvr32.exe to register a dll using VBA? My software is in access (dont blame me, blame the company). Access for some reason always references the old version of the DAO library. After about 2 hours of searching the internet, someone suggested registering the library, and viola it worked. It cut down ...

Invalid Argument Error: MSAccess and SQL

I am trying to access certain lines from my SQL database from MSAccess and I keep getting an Invalid Argument Error on this line: Set rs = CurrentDb.OpenRecordset("SELECT TimeID " & _ "FROM tblLunchTime " & _ "WHERE ProductionID = prodSelect AND EndTime is NULL AND StartTime < dateAdd('h', 3, NOW())", [dbSeeChanges]) Is someth...

"User-defined type not defined" for Excel Range Using Late Binding In Access 2003

Hello, I am trying to write a VBA script which imports all of the Excel files in a folder into a table in Access 2003, first checking if they have been imported or not. That part is fine. The issue I run into is clearing out some of the formulas that don't get used on the spreadsheet which causes difficulty when Access tries to import t...

MS Access 2007/2003 - Referencing a control on a sub form, from the parent form

So if I want to reference a control (like a text box) on a sub form, from the CBF of the parent form, how should I do this. me.SubForm.SubControl gives me an error. thanks justin ...

Randomly Assigning Positions

Hey, Here's my basic problem. Let's say I have 50 employees working on a certain day, and I want my program to randomly distribute them to a "position" (I.e.: front desk, phones, etc) based on what they have been trained on. The program already knows what each employee has been trained on. What is the best method pragmatically to go thro...

how to update a recordset in a subform using vb (I am getting error #3426) in Access 2007

hello, I am trying to update a control in a subform. Actually I am calculating the number of months. here is the code: (which doesn't work!) While (Not Me.Form.Recordset.EOF) months = Round((Me.End - Me.Start) / 30, 0) Form_FinanceSubform.[number of months] = 0 Me.[number of months] = months Me.Form.Recordset.MoveNext Wend the error ...

Access 2007 forms with parameterized RecordSource

I'm sure there's a simple solution to this, but it seems to elude me. So I have a form with a RecordSource of SELECT * FROM Table1 WHERE id=[@id]. (Yes, I know SELECT * is evil; it's just an example). Obviously the default behavior of this form is that upon opening, an input dialog will prompt for the "[@id]" value. But what I would l...

Sanitizing a string in Access 2003 SQL: Problem with '

I'm writing a query that has to count the number of students enrolled in a course, and the way I'm doing it is like this: DCount("[student/course table].[Student ID]","[student/course table]","[StartDate] = #" & [Course Start Date] & "# AND Location = '" & tblCourseDetails.Location & "' AND [Course Number] = '" & [Course Number] & "'") ...

alternating row colors/numbers in Excel - VBA

Hey guys, So I am working on a reporting tool in Access. It queries the local tables and creates a Excel document (through VBA) and makes an Excel file. I use the following code to color alternative code and it works beautifully For a = 1 To rs.RecordCount With ExcelSheet .Cells(a + 1, 1) = a .Cells(a ...

optimizing this code in VBA

Hi guys so I was browsing SO and one of the topics was "how to tell if a student coded this".. well I am a student working for a pretty big company as an intern. I recently coded a reporting tool for them in Access and have a question about a piece of code 'get the dates' 'check if both date fields are filled out' If A_AfterDateTxt...

Determining if a path is a network path VBA

Hi developing an application in Access. The access file will be located on a db however when users need to use it, I want them to copy it on there desktop. If they do run it off the G:\ drive (our networked folder), it should give them a message. So are there Win API that will help me solve this? I am going to put this code in the For...

doCmd.openreport where clause prompting

I have a simple piece of code written to open a report. Private Sub FormButton_Enter() Dim strwhere As String strwhere = Me.FormText DoCmd.Openreport "rtpname",acViewPreview,,"ColumnName=" & strwhere End Sub I am getting two popups , even though i pass the filter criteria from the form. Please advice. ...