Private Sub DeleteCategories()
Dim objNS As NameSpace
Dim objCat As Category
Set objNS = Application.GetNamespace("MAPI")
If objNS.Categories.Count > 0 Then
For Each objCat In objNS.Categories
Set objCat = Nothing
Set objNS = Nothing
I am calling Form_BeforeUpdate directly from a Close (Form) button's onClick Event, to handle various circumstances when the form is only partially filled in but the User wants to bail out. Under certain (perfectly feasible) circumstances, Form_BeforeUpdate is correctly setting Cancel to True within itself, but it is not being passed back to the calling Sub! Subroutine parameters are ByRef by default, but setting Cancel explicitly to ByRef in the definition of Form_BeforeUpdate does not change the misbehavior. Here are the two Subs:
Private Sub cmdClose_Click()
Dim Cancel As Integer
If Cancel Then
If MsgBox("This record contains errors. Do you wish to correct them before closing the form?", vbYesNo, "Errors") = vbYes Then
If Me.NewRecord Then
MsgBox "The current record will be discarded.", vbInformation
MsgBox "Any changes made to the current record will be discarded.", vbInformation
blMayClose = True
DoCmd.Close acForm, Me.Name
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim rst As New ADODB.Recordset
If Me.NewRecord Then Contact_Pt = lbxContacts.Value
Set rst = New ADODB.Recordset
rst.Open "SELECT ID FROM Assets WHERE package_Pt = " & ID, CurrentProject.Connection, adOpenStatic, adLockReadOnly
If Not (rst.EOF And rst.BOF) Then
If IsNull(Start_Date.Value) Or IsNull(End_Date.Value) Then 'this is where Cancel gets set to True
MsgBox "You must enter start and end dates for the package before saving it.", vbExclamation, "Dates Missing"
Cancel = True
ElseIf End_Date.Value <= Start_Date.Value Then
MsgBox "The end date must be after the start date.", vbExclamation, "Invalid dates"
Cancel = True
Set rst = Nothing
Using the parentheses is forcing VBA to evaluate the bracketed expression (in this case, your variable Cancel) and then pass it as ByVal into the subroutine. Ergo the value remains unchanged in the calling sub.
See Matthieu Guindon's solution here [^] for a fuller explanation
Thanks! I had given up and used a workaround (which actually turned out to have other advantages, so it wasn't all bad). VBA's requirement that you not surround sub/function arguments with parens (unless you make an explicit Call) is always catching me out, since every other language I use require the parens. Fortunately, it mostly affects implicit calls with multiple arguments, where putting in the parens provokes an immediate syntax error in the editor. This case is a particular pain since the bad syntax is not flagged but nevertheless changes the meaning of the call.
from my Visual Basic Scriot ( Visual Studion 2015) wenn i call my funktion from ma scrip like tis
Private Sub Request_1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Request_1.Click
Dim r As Integer
Dim data As String
Dim ID As String
Dim sender As String
sender = "DatO"
If ID_KS_1.Text <> "" Then
ID = "ID_KS=" & ID_KS_1.Text & ","
sender = "KS_Trifact"
ErrorText.Text = ""
If obj Is Nothing Then obj = CreateObject("NmsTaskDbSv.64Bit_NmsDbData")
'UPGRADE_WARNING: Couldn't resolve default property of object obj.Request. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
'r = obj.Request(15101, "1.0", sender, "customerservice/customer", ID & "ACCOUNT=" & Par_1_1.Text, "test")
r = obj.Request(15101, "1.0", sender, "customerservice/customer", ID & "ACCOUNT=" & Par_1_1.Text, (data))
If (r = 0) Then
Result_1.Text = data
it seams to work but rhe response dues not arrive in the data variablele wenn i make the call j = CreateObject without () lik this
Hi everyone, my name is Maurizio and my question is this
In VB I would like to know how to create one or more objects of the same type at run time.
1) In a form I insert a textbox1 and a button
The purpose of my request is to know how: By pressing this button
It should bring up another textbox and so on.
that's all !!!!
If I remember correctly I used the New function
But it seems that this does not work in vb.
Could you please help me Thanks
Greetings from Maurizio
You can do it like suggested by Dave - the other way could be (perhaps easier to code and to maintain for you) :
- Create the Textbox you want to bring up from the beginning with the Designer.
- Set it's Visible-State to False
- When pressing the Button set it's Visible-State to True.
In this case you are able to make all the relevant connections.
You don't need to modify the Controls-Collection from the Form, catch the Events from the new Control and so on ...
Thank you to everyone for your interest
But it wasn't the answer I would have expected from experienced people like you.
/p.s) But if instead of cloning I asked for a sort of (Textbox) Dynamic with at least 5 possibility of creating (Textbox) on request!
What would have changed?
I'll explain :
If I press the key inserted in the form and I create the first dynamic (Textbox)
How can I go about creating a new one at least five times the same size as the first?
I tried to write something like this; But it is valid only for the first dynamic (Textbox)
Therefore I would miss being able to create all the others every time I press the create button.
They all "default" to the same size and location unless you "change" the property's default value at "construction" time or subsequently. Based on your problem description, that's all that "experience" dictates. If your requirements are more complex, you have failed to articulate them; perhaps it needs "reflection"; but that requires "experience".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
I have created a program that is intended to be used by multiple users (each on their own computer) who access the same SQL database. I have also created a separate updater program to sit alongside the main application. However, I am unsure how to check if there are any users in the main program before the update is run. (This is easy to do on a single user application but not sure on multi-user).
Sorry, but you wrote that every client application is opened on client machine. You don't have to care about other clients.
So, if a single instance of client application is running on client machine, you can close it via updater.
I think what you need to research is the topic of concurrency.
One way to implement this is to have a Modify Date on the primary record.
1) Read the table entry along with the modify date/time.
2) When updating the database, compare the original date/time with the value currently stored, if the date/time has not been changed, then it is OK to perform your update. (Rollback)
During your update you would set the modify date/time to the current date/time. (GetDate() )
Something like that.
Last Visit: 29-Oct-20 13:47 Last Update: 29-Oct-20 13:47