Modules & VBA :: DoCmd Works In Immediate Window Not In Sub

Nov 14, 2014

Why does the DoCmd.TransferDatabase work in the Immediate window, but not in the Sub, which has always worked in the past?

Code:
Public tblname As String
Public tblNewname As Variant
Public pstrDatabasePath As String
Public Const dbType As String = "Microsoft Access"

[code]....

ERROR MESSAGE: 3125 '' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.

View Replies


ADVERTISEMENT

Hiding Access Window With DoCmd.runCommand AcCmdAppMinimize

Mar 28, 2007

Ok, I finally have it working the way I like. It's really slick - the main form (set to "PopUP" and with docmd.runcommand accmdappminimize line in the On_Open event) opens with customized icon (in titlebar and in windows taskbar) and behaves like a standalone program (you only see Access the first few seconds during opening before it's minimized).

The form can be minimized to windows taskbar and clicked to restore it (form's maximize button is disabled, for appearance sake). it can also be accessed via the alt-tab windows menu, where it also appears with a custom icon. so it's really slick, it behaves just like a standalone app. read on for the ", but..."

I also wrote 2 functions to handle reports.

1st (fnOpen, I also use it for forms, etc. via arguments, but only the reports have the following logic). This one closes my main form, maximizes Access (which has all menus/toolbars disabled, so it doesn't really look like Access, looks like a report viewer). This function is placed into all report buttons' On_Click event with report name as argument and object type (3 for report, because 0=table, 1=query, 2=form, 3=report in my fnOpen).

2nd. (fnCloseReport) is placed into all reports' On_Close event. This function opens my main form again on the tab from which report was called. It works, but herein lies the problem: after the form reopens, it no longer has the whole application's custom icon, but the Access "form" icon. And after this, if minimized to windows taskbar it actually minimizes as resized mini-window above the Start button (as has been described by others, just as it would within Access it it were visible) and Access appears minimized in the windows taskbar, so somehow the whole cool "standaloneness" is turned off.

I wonder if anyone has some suggestions for this. I spent some time researching and testing this and really like the functionality. When the form is displayed without Access, it cannot be right-clicked (at all), which is very useful (although I know there are other ways of protection).

BTW, all my other windows (all popup/modal) appear on top of the main form with no problems. I have "File Open" and "Save As" windows common dialogs that my app calls (via API) and I also have a custom form acting as dialog box (I use the acDialog intrinsic constant when I open it from code). so mutliple windows are not an issue as some have suggested.

Thanks in advance!

View 3 Replies View Related

DoCmd.OpenForm Fails If Access Is Not The Active Window

Jun 13, 2006

I have an Access 2000 application which, on startup, always launches a 'switchboard' form and sometimes gets information from the user during the startup. Both forms are opened with VBA using DoCmd.OpenForm; the switchboard opens as acNormal and the input form (when used) as acDialog.

Under normal circumstances this works fine.

If, however, the Access window ceases to be the active window in Windows (e.g. the user selects another application's window in the taskbar) the forms do not open (all other VBA code runs correctly).

Any ideas?

Simon

View 2 Replies View Related

Modules & VBA :: Multiple Conditions In A DoCmd

Oct 11, 2013

I have a Customer Issue form that writes the following into one table named Table1: Date, Customer Name, Ticket number, Agent, Issue and Comments. This is very simple.

All of this is filled in from a form that has links to 3 other tables for drop downs; Customer Name, Agents, Issues. This is working perfectly.

What I want to be able to do is generate a report based on a date range for a particular agent. Say 9/1/2013 - 9/30/2013 for John Doe.

For the report portion, on the form I have to combo boxes, one for start date, one for end date. I also have a drop down for selecting the agent. When I click a button on the form named Report, It will generate a preview of the report.

Here is the problem. I can get this to generate a report based either on the date range, which gives me all of the agents, or by agent, which gives me all of the dates. I can't get it to do both.

Here is some code that I have on the Report button:

DoCmd.OpenReport "AIReport3", acViewPreview, , "[Agent]=" & Me.Agent
This is the code that will let me choose the agent, but gives me all dates.

If I change this code to this:
DoCmd.OpenReport "AIReport3", acViewPreview, , "[DateRptd] Between #" & Me.cboFrom & "# And #" & Me.cboTo & "#"
It will display all issues in the date range, but gives me all agents.

I was thinking I should be able to combine them with an AND or an & to get it to use both the agent and date fields, but I can't get this to work.

Something like: DoCmd.OpenReport "AIReport3", acViewPreview, , "[Agent]=" & Me.Agent And "[DateRptd] Between #" & Me.cboFrom & "# And #" & Me.cboTo & "#"

or

DoCmd.OpenReport "AIReport3", acViewPreview, , "[Agent]=" & Me.Agent & "[DateRptd] Between #" & Me.cboFrom & "# And #" & Me.cboTo & "#"

View 3 Replies View Related

Modules & VBA :: How To Execute A DoCmd From Within A Connection State

Feb 24, 2014

I'm trying to do something with Excel and Access. From Excel 2007, I need to open an Access database exclusive, import from Access to Excel a table, do some work within Excel, and then start a macro within the Access database. Briefly, here’s what I have

1) To open the database exclusively:

Set connDB = New ADODB.Connection
With connDB
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Mode = adModeShareExclusive
.Open strdbpath 'path to database
End With

2) To import from Access:

strSQL = "SELECT * FROM [" & tn & "];" 'tn is Access table
If connDB.State = adStateOpen Then
Set objRS = New ADODB.Recordset
objRS.Open strSQL, connDB, adOpenForwardOnly
On Error Resume Next
objRS.MoveFirst
If Err.Number = 0 Then
On Error GoTo 0
fieldCnt = objRS.Fields.Count
For fieldNum = 0 To fieldCnt - 1
ws.Cells(1, fieldNum + 1).Value = objRS.Fie(fieldNum).Name
Next fieldNum
ws.Cells(2, 1).CopyFromRecordset objRS
End If
End If

3) To start a macro:

DoCmd.RunMacro "Daily Import"

Everything seems to work until the ‘DoCmd’ statement where I get a “You can’t carry out this action at the present time” error message.

View 8 Replies View Related

Modules & VBA :: Edit Dataset Works And Add A New One

Aug 4, 2013

I have an edit button in my form which activates VBA, collects all data from the fields and edit the dataset. Everything work fine except the case that next to the edit access adds a new record as well with exactly the same data.

This is my code :

Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("select * from tbllocations where locationid = " & cdkey)

[code]...

I checked every parameter and it seems everything is OK which surely is the base for the correct edit of the dataset. locationid is the key of the table.

View 3 Replies View Related

Modules & VBA :: Search That Works Unless Beginning With I

Jul 8, 2013

I have a simple bit of code that searches for a [User Name] field the basic idea is I place a field called "search" on a form and set its on change to

Private Sub Search_Change()
Search.SetFocus
strtarget = Search.Text
If strtarget < "a" Then strtarget = "a"
[User Name].SetFocus
DoCmd.FindRecord strtarget, acStart, False, acSearchAll, False, acCurrent, True
Search.SetFocus
Search.SelStart = 100
End Sub

it takes the text entered in the search field and calls it Strtarget then resets focus on the field I want eg [user name] once the search has done it resets the focus on the search field so you can carry on typing this works very well unless the search string starts with a letter I.

View 8 Replies View Related

Modules & VBA :: DCount Works But DSum Doesn't

Jun 19, 2013

Mycode works great when I use the DCount function, but fails when I change it to DSum which errors with: Error 94 - invalid use of null.

dblCntr = DSum("[intEventCount]", "tblResourceEvents", "[ResourceEventTypeID] = " & myKey & " AND [TimeFrameID] = " & Me.cbo1)

The entire table has valid data - no nulls. myKey and Me.cbo1 both have correct values.

View 2 Replies View Related

Modules & VBA :: Code That Creates A Long String That Works Most Of Time But Sometimes Gets Cut Short

Nov 5, 2014

I have the following code that creates a long string that works most of the time but sometimes gets cut short. I can't understand why it does this. When it cuts the string short it cuts it short in the same place. Everything gets in the string up to/or about the following code '</Practice Name>'This string is needed to upload info to a server.

Code:
dim msg as string

msg = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & vbCrLf & _
" <soap:Body>" & vbCrLf & _
" <UpdateDataForScreens xmlns=""http://mdtoolboxrx.com/"">" & vbCrLf & _
" <PatientObj>" & vbCrLf & _

[code]....

View 10 Replies View Related

Modules & VBA :: Hide 5 Buttons Depending If User Has Permission Which Works Fine

May 14, 2014

i have the following code that hides 5 buttons depending if the user has permission which works fine.im trying to incorporate an IF statement if there is only 1 of the buttons visible then to automatically click the button. but if there is more than 1 do noting?

Code:

Private Sub Form_Open(Cancel As Integer)
Dim rsO As DAO.Recordset
Set rsO = CurrentDb.OpenRecordset("SELECT tblUserPermission.UserFK, tblUserPermission.CompanyFK, tblUserPermission.Permission " & _
"FROM tblUserPermission INNER JOIN tblUser ON tblUserPermission.UserFK = tblUser.UserPK " & _
"WHERE Username = '" & Me.txtName.Value & "'")

[code]...

View 3 Replies View Related

Modules & VBA :: How To Set The Active Window

Mar 30, 2015

I have created a form that will print the active report. I have managed to make it look for the active report, but it won't find it because there's no report active, even though I have the report open. How do I make my report be active when I open it? (In a way that whichever report I open will become the active window so that my form will e-mail the report that is currently open)

View 2 Replies View Related

Modules & VBA :: How To Change Cmd Window Style

Nov 11, 2014

I am using the following code to open a cmd window and wait while it executes, but I would like to run the cmd window minimized but cannot work out how to do that

Code:

Option Compare Database
Option Explicit
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long

[code]....

how to change the cmd window style.

View 2 Replies View Related

Help: Pass Argument From Child Window To Parent Window?

Feb 15, 2005

Hi,

I have a parent window which upon clicking on a button will pop-up a child window containing a listbox. The listbox recordsource is a subset of the parent window. I want the user to select a record from the listbox which will load the selected record onto the parent window.

How does one pass argument back from child window to parent window?

From parent window to child window, I used
docmd.openform ,,,,,,[argument] and me.openargs in the child window

thanks in advance.

View 4 Replies View Related

Modules & VBA :: Static Shell Function Call Works But Dynamic Call Fails

Sep 4, 2013

I'm having to recode some old MS Access DBs so they will run in the following environments:

Office 2000 on WinXP
Office 2003 on WinXP
Office 2010 on WinXP
Office 2000 on Win7
Office 2003 on Win7
Office 2010 on Win7

When I wrote my code for Office 2000 on WinXP things were simple because directory paths were the same across all computers and I could hard code pathing when using a shell command to launch other files.

My new approach is to make a function call to the Windows registry to determine the default executable and path for opening a file based upon its extension (see apicFindExecutable in basWindows API module).

I'm able to use code to create a shell call and debug print it to the immediate window. If I put my cursor in the immediate window at the end of the shell call and hit [enter] the external file will open as desired. If I try to open the external file directly through code, I get a file not found error.

To recreate the error take the following steps:

(1) browse to files that are accessible from your computer
(2) click the PREPARE DATA AND OPEN MAIL MERGE DOCUMENTS command button

Shell function call is made by the fnOpenFile function located in the basOpenFile module. There has to be a trick here that I'm missing.

View 5 Replies View Related

Modules & VBA :: Open The Export To Excel Window?

Aug 21, 2013

Is there a command that I can use to export a spreadsheet to Excel...

I could use docmd.transferspreadsheet

however that would also mean i would need an input window where users would need to manually put in the location they wish to save to...

Instead, could i not get a "SaveAs" command window or a file browser at least for them to search that way?
Alternatively, If it was possible to use VBA to pop up the "Export - Excel Spreadsheet" window, that would be just as good.

View 2 Replies View Related

Modules & VBA :: OnClick To Open The Image In A Window

Jun 7, 2013

I am new to VBA for access. I am working on a form as a user interface. I have added an picture to the form and it will change, according to the selection in the combobox. It looks small, and not clear because of the size, and each image has different size. I would like to know if there is a VBA code that will allow me to click on it, and then it will open in another window so it is bigger with the right sizes.

View 6 Replies View Related

Modules & VBA :: How To Minimize Access Window And Open The Form On Top

Nov 16, 2014

Who can tell me how to minimize Access window while it's form is on top of other open windows (e.g. other applications which are maximized like Excel). By using acCmdAppMinimize command, only the Access window is minimized and if other applications are maxmized, they will be on top. So is there any vba solution to do what I explained?

View 4 Replies View Related

Modules & VBA :: Form Window To Popup On Opening Database

Dec 4, 2013

How I configure my Form Window to pop up as soon as I open my Access Database?

View 3 Replies View Related

Modules & VBA :: Login To Database - Close A Modal Popup Window

May 2, 2014

I've tried to add some basic login (not really security) to my database so that when a different name is entered into the login box a different form is opened.

I got this working but the login form stays in foreground and I can't click anything behind it and can't get to the design view to change any properties of anything.

I've also changed this login form to the startup item so it always loads when i start the database.

Is there way to get back to the design view or do i have to start again from my backup?

View 2 Replies View Related

Modules & VBA :: Way To Grab Text From The Window That Shows Location Of File

Jun 18, 2015

I want to find a way to grab the text from the window that shows the location of the file using vba in Access.

View 3 Replies View Related

DoCmd.RunApp

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

DoCmd.TransferSpreadsheet

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

DoCmd.RunSQL

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

DoCmd Problem In ASP

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

Forms Are Opening In Same Window / How To Open Forms In Different Window

Oct 21, 2013

My application is developed in Access 2003 version. Recently we moved from Access 2003 to Access 2010. Now users are facing usability issues like - in Access 2003 all the forms are opening in different windows and they can move to forms easily. But in Access 2010 all the Forms are opening in same window, if they want to move to different forms then they need to close the current window or press ctrl+F6. How can I enable/open forms multiple window in Access 2010.

View 3 Replies View Related

DoCmd.Maximize... Not Working

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







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