I have a VB6 application working with.
This application uses ODBC to access a Microsoft Access database.
I am sure that the database string is correct as the database contains the information used to login and the login works just fine. I also have the same string at every instance.
However, at a certain point the ODBC driver error-"Data source name not found and no default driver specified" appears...The issue is:
This occurs whenever I press a specific button. This button opens a form:
Private sub Munubttn_Click()
frmLog.Show
End Sub
However, in the form frmLog, I placed a message box as the first command under the Form_Load() sub. Now whenever the button is clicked, I get the error, just before the message box. As such, I do not know where this error originates. So I suppose the question is, what code does the form execute just before it loads? Any help would be appreciated.
So I suppose the question is, what code does the form execute just before it loads?
The only code that would be executed would be the class initialize sub. Given your described scenario, the problematic logic is likely in a Class_Initialize sub within the frmLog Form.
Related
I have an Access 2007 form which contains a combo box with the following Rowsource:
SELECT qryProjectsIHaveAccessTo.projID, qryProjectsIHaveAccessTo.projName
FROM qryProjectsIHaveAccessTo
WHERE (((qryProjectsIHaveAccessTo.projSupportTracker)=False));
The query qryProjectsIHaveAccessTo uses a user-defined function as the criteria for one of the columns. This function detects if a Startup routine has been run, and if not runs it.
The problem I have is this: if I SHIFT+open the database and open the form in DESIGN mode, for some reason the user-defined function starts running. This then causes errors as the Startup routine it calls tries to open a form (presumably Access cannot open a form while it is in the process of opening another form in Design mode) and sometimes I am not able to CTRL+BREAK out of it.
The same thing happens when I go to save the form in Design mode.
If I remove the RowSource string from the combo box, this no longer happens. But why would a function which is called in a query included in a control RowSource get fired when the form opens in Design Mode?
Any ideas anyone? Thanks for reading!
When you open a form in design view, Access validates that the form record source is still there, and that all the query fields that are bound to form controls are still there.
If some of these checks fail, Access shows the small green triangle on the bound controls with problems.
While doing this check, it runs the UDF in the query.
As was said in the comments, calling a startup function does very much not belong into UDFs that are called from a query. Put it into a function that is called by an AutoExec macro.
I have an Access database where I have code on the On Load event of the main form to set focus to a textbox and load a 'new' record. The code is:
Private Sub Form_Load()
'Makes it so that when frmDiversion_Review loads, it defaults to a new record
DoCmd.GoToRecord , , acNewRec
Me!FromDate.SetFocus
End Sub
FromDate is an unbound date field used in a search/filter section on the header of the form.
I've split the database, and have an .accde file ready to go, but I've noticed that when I close Access when in the .accde file it gives me the following error:
"The expression On Load you entered as the event property setting produced the following error:
****NameOfDatabase**** can't move the focus to the control FromDate."
It does not give an error number.
The code is compiled, and I only get this error using the .accde file. I'm at a loss why the On Load event is even firing when I close Access. Any ideas?
A few weird scenarios may produce this (such as something relating to other forms being closed when you close out...) having references to this form that cause it to open. Hard to say from here.
But there is an easy out... just add this line at the start of the routine
On Error Resume Next
This is safe provided you know there are no real errors in the routine ever, excepting this annoying one that doesn't actually mean anything. If real errors can occur, you will no longer see them if you add this easy-out.
Personally, I'd prefer to find the cause and address it, not least because it seems other forms are trying to open this form while you're busy closing the app, which is an unsettling thought. But... when all else fails, it's a solution.
I have a program written in vb.net that contains a form. The form has 5 label controls and 1 button. I am using this program as my startup script file on my network (server 2008r2). When a user signs in to one of the servers the script executes and runs fine until it gets to the form.showdialog command. At that point nothing happens.
I have a try/catch like below:
Try
...write message1 to file in SQL database
Form1.ShowDialog()
...write message2 to file in SQL database
Catch ex As Exception
...write error message to file in an SQL database
End Try
message1 writes fine and that's it.
Now if I run the exe script file directly from one of the servers by double clicking on it the form displays fine.
If anyone can provide some insight I sure would appreciate it. This one has me stumped.
.ShowDialog causes the application to wait for the form being shown to no longer be shown. An example would be a prompt for a value, the form that threw the prompt would not progress past the .ShowDialog while the prompt remained open.
Since it sounds like you're wanting the code to progress without user involvement, my thought would be to:
- Move the code prior to Form1.ShowDialog into the Load code (Handles MyBase.Load) for Form1
Make sure Form1 is the Startup Form for the application
Add all code currently following Form1.ShowDialog to the .Shown event code for Form1
In the program I'm writing, there is just one form. I've made a user control visible and it contains several buttons. One of the buttons is supposed to close the form when clicked. I can't find any way to do this without getting the error: "Cannot access a disposed object. Object name: 'ShapeContainer.'" I'm pretty sure I understand the problem; after the form has been closed, the user control no longer exists, so there's an error when Form.Close() (I've tried Form.Dispose() too) has completed and it tries to go back to the code inside the button click event. Does anyone know how I could accomplish closing the form through this user control's button without getting the error?
Okay I'm pretty new to vb but I think if you get rid of the Form.Dispose() & Form.Close then try Me.Close() as you are referring to the current Form that the button control is located on.
You Should have got this error:
(Error 1 'NameSpace_.Form1' cannot refer to itself through its default instance; use 'Me' instead.)
I need to close an Excel userform using VBA when a user has clicked a submit button and operations have been carried out.
How can I close a Userform from itself?
I have tried this but it returns a 361 error.
Unload Me
As specified by the top answer, I used the following in the code behind the button control.
Private Sub btnClose_Click()
Unload Me
End Sub
In doing so, it will not attempt to unload a control, but rather will unload the user form where the button control resides. The "Me" keyword refers to the user form object even when called from a control on the user form. If you are getting errors with this technique, there are a couple of possible reasons.
You could be entering the code in the wrong place (such as a
separate module)
You might be using an older version of Office. I'm using Office 2013. I've noticed that VBA changes over time.
From my experience, the use of the the DoCmd.... method is more specific to the macro features in MS Access, but not commonly used in Excel VBA.
Under normal (out of the box) conditions, the code above should work just fine.
Without seeing your full code, this is impossible to answer with any certainty. The error usually occurs when you are trying to unload a control rather than the form.
Make sure that you don't have the "me" in brackets.
Also if you can post the full code for the userform it would help massively.
Unload Me only works when its called from userform self. If you want to close a form from another module code (or userform), you need to use the Unload function + userformtoclose name.
I hope its helps
It should also be noted that if you have buttons grouped together on your user form that it can link it to a different button in the group despite the one you intended being clicked.