473,788 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save button using toolbar

143 New Member
Hello everyone,
I m using some button using toolbar such as Add,Save,View,. ... my save button is not working.... it doesnt give me any error but does not save to my database.... or showing in my gird... Plz Help
here is my code for save button
Expand|Select|Wrap|Line Numbers
  1. Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
  2. On Error GoTo ChkErr
  3.     If Button.Index = 1 Then
  4.             Mode = "Add"
  5.             Call AddMode
  6.             Call ClearControl
  7.             Toolbar1.Buttons.Item(1).Enabled = False ' Add
  8.             Toolbar1.Buttons.Item(2).Enabled = False ' View
  9.             Toolbar1.Buttons.Item(3).Enabled = False ' Sort
  10.             Toolbar1.Buttons.Item(4).Enabled = False ' Edit
  11.             Toolbar1.Buttons.Item(5).Enabled = True ' save
  12.             Toolbar1.Buttons.Item(9).Enabled = True 'Exit
  13.  
  14.               End If
  15.  
  16.     If Button.Index = 4 Then
  17.         'If Val(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.RowSel, 8)) = "0" Then
  18.             Mode = "Edit"
  19.             Toolbar1.Buttons.Item(5).Enabled = True ' save buton
  20.               Call Enable
  21.         Else
  22.             MsgBox " Cannot Edit "
  23.         End If
  24.  
  25.     If Button.Index = 5 Then
  26.  
  27.             Call SaveMode
  28.             Call ClearControl
  29.             Call Desable
  30.             MsgBox " Record Saved For Id '" & txtId.Text & "'"
  31.             Toolbar1.Buttons.Item(5).Enabled = False
  32.             Toolbar1.Buttons.Item(1).Enabled = True ' Add
  33.  
  34.             Call Address
  35.     End If
  36.  
  37.     'End If
  38.  
  39.     If Button.Index = 2 Then ' View
  40.         'Toolbar1.Buttons.Item(7).Enabled = False ' Final
  41.         Toolbar1.Buttons.Item(1).Enabled = False ' Add
  42.         Toolbar1.Buttons.Item(4).Enabled = True ' Edit
  43.  
  44.     End If
  45.  
  46.  
  47.  
  48.     If Button.Index = 7 Then ' Cancel
  49.             Db.Execute "Update Address"
  50.             Call Address
  51.  
  52.     End If
  53.  
  54.  
  55.     If Button.Index = 9 Then ' Exit
  56.             Unload Me
  57.     End If
  58.  
  59. Exit Sub
  60. ChkErr:
  61.     If Err.Number > 0 Then
  62.     MsgBox Err.Number & vbNewLine & Err.Description
  63.                Call ErrHand(Me.Caption, "cmdSave_Click")
  64.  
  65.     End If
  66. End Sub
  67.  
  68.  
  69. Public Function SaveMode()
  70. 'On Public Function SaveMode()
  71. If Mode = "Add" Then
  72.     ' To Get ReqNo from Mslastdoc
  73.     Dim Rs As New ADODB.Recordset
  74.         If Rs.State = adStateOpen Then Rs.Close
  75.          Rs.Open ("SELECT * FROM MsLastDoc where YY ='" & FinancialYear & "'"), Db, adOpenKeyset, adLockPessimistic
  76.                   txtId.Text = Rs("LastDocNo").Value + 1
  77.              Rs.Close
  78.          ' End
  79.  
  80.     ' Save LastDoc
  81.     Dim LastDoc As New ADODB.Recordset
  82.     Dim DocNo As Integer
  83.                 DocNo = Val(txtId.Text)
  84.                 If LastDoc.State = adStateOpen Then LastDoc.Close
  85.                 LastDoc.Open ("Select * From MsLastDoc where YY ='" & FinancialYear & "' "), Db, adOpenKeyset, adLockPessimistic
  86.                 Db.Execute "Update MsLastDoc set LastDocNo ='" & DocNo & "' where YY ='" & FinancialYear & "' "
  87.     ' End Save
  88. End If
  89.  
  90. Call SaveAddress
  91. Call ClearControl
  92.  
  93. End Function
  94. Public Function SaveAddress()
  95.     Db.Execute " Delete from Adress where Id = '" & txtId.Text & "' "
  96.  
  97.         Dim RsAddress As New ADODB.Recordset
  98.        'If RsReqHdr.State = adStateOpen Then RsReqHdr.Close
  99.         RsAddress.Open ("Address"), Db, adOpenKeyset, adLockPessimistic
  100.         With RsAddress
  101.         RsAddress.AddNew
  102.                 .Fields("Id") = Val(txtId.Text)
  103.                 .Fields("Addressof") = Val(cmbadrof.Text)
  104.                 .Fields("Address") = Val(txtAddress.Text)
  105.                 .Fields("city") = Val(txtCity.Text)
  106.                 .Fields("Pin") = Val(txtPin.Text)
  107.                 .Fields("entrydt") = Format(DTPentrydt, "DD-MMM-YYYY")
  108.                 .Fields("closedt") = Format(DTPClosedt, "DD-MMM-YYYY")
  109.  
  110.             .Update
  111.                 End With
  112.             RsAddress.Close
  113. End Function
  114.  
Jun 16 '08 #1
14 3688
Dököll
2,364 Recognized Expert Top Contributor
Greetings, squrel!

I am not sure what the problem is, are you having problems with just your save mechanism? Did you know you can run the code in debug mode to follow what is happening. Please write if you need to know how to do that.

Do stay tuned for a better answer on this one, like I said I am not certain how this could go.

In a bit!

Dököll
Jun 17 '08 #2
squrel
143 New Member
plz tel me how to run it in a dubug mode... and non of my button is working... dont knw why? thank u
Jun 17 '08 #3
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

First Remove the error Handling and Run the Code.
Keep a BreakPoint on First Line of the Code.
and Check the Run-Sequence..

Regards
Veena
Jun 17 '08 #4
squrel
143 New Member
Hi... i have changed the code to this but still i have error in this line :

'txtAddressId.T ext = GetNextCode("Ad dress", "AdrID")


why my getnextcode is not working? it gives me the error of Sub or function not defined? i dont get wht is the problem.... plz help... thankx



Option Explicit

Private Sub Form_Initialize ()
On Error GoTo ChkErr
Db.Close
Db.ConnectionSt ring = pStrConnectionS tring
Db.ConnectionTi meout = 0
Db.Open
Db.CursorLocati on = adUseClient
DoEvents
Exit Sub
ChkErr:
If Err.Number > 0 Then
MsgBox Err.Number & vbNewLine & Err.Description
Call ErrHand(Me.Capt ion, "Form_Initializ e")
'Resume Next
End If
End Sub
Private Sub Form_Load()
On Error GoTo ChkErr
FormUpdateSQL1. ConnectionStrin g = pStrConnectionS tring
FormUpdateSQL1. TableName = "Address"
FormUpdateSQL1. FieldList = "AdrId;AdrOf;Ad dress;City;Pin; Entrydt;Closedt ;Ind;"
FormUpdateSQL1. ControlList = "txtId;cmbadrof ;txtAddress;txt City;txtPin;DTP entrydt;DTPclos edt;ChkInd;"
FormUpdateSQL1. ViewFields = "AdrId;AdrOf;Ad dress;City;Pin; Entrydt;Closedt ;Ind;"
FormUpdateSQL1. FormatString = "AdrId;AdrOf;Ad dress;City;Pin; Entrydt;Closedt ;Ind;"
FormUpdateSQL1. DoVisible 4, False
FormUpdateSQL1. DoVisible 6, False
FormUpdateSQL1. DoVisible 8, False
FormUpdateSQL1. AllowEdit = True
FormUpdateSQL1. Refresh
cmbadrof.Enable d = False
Call Grid_Data
Exit Sub
ChkErr:
If Err.Number > 0 Then
MsgBox Err.Number & vbNewLine & Err.Description
Call ErrHand("Addres s", "Form_Load" )
'Resume Next
End If

Grid_Data
End Sub
Public Sub Grid_Data()
On Error GoTo ChkErr
Adodc1.Connecti onString = pStrConnectionS tring
Adodc1.RecordSo urce = "Select AdrID as ID,Adrof,Addres s,City,Pin,entr ydt as EntryDate,close dt as CloseDate from Address"
Adodc1.Refresh
MSHFlexGrid1.Co lWidth(1) = 800
MSHFlexGrid1.Co lWidth(2) = 1000
MSHFlexGrid1.Co lWidth(3) = 2000
MSHFlexGrid1.Co lWidth(4) = 1000
MSHFlexGrid1.Co lWidth(5) = 800
MSHFlexGrid1.Co lWidth(6) = 1000
MSHFlexGrid1.Co lWidth(7) = 2000
MSHFlexGrid1.Re fresh
Exit Sub
ChkErr:
If Err.Number > 0 Then
MsgBox Err.Number & vbNewLine & Err.Description
Call ErrHand("Addres s", "Grid_Data" )
'Resume Next
End If
End Sub

Private Sub FormUpdateSQL1_ AddClick()
cmbadrof.Enable d = True
'txtAddressId.T ext = GetNextCode("Ad dress", "AdrID")
cmbadrof.Enable d = True
ChkInd.Value = 1
End Sub

Private Sub FormUpdateSQL1_ AfterControlsEn abled()
cmbadrof.Enable d = True
End Sub
Private Sub FormUpdateSQL1_ AfterUpdate()
cmbadrof.Enable d = False
Call Grid_Data
End Sub
Private Sub FormUpdateSQL1_ BeforeValidate( )
If cmbadrof.Text = "" Then
MsgBox " Enter the selected address"
cmbadrof.SetFoc us
Exit Sub
FormUpdateSQL1. CancelEvent = True
End If
End Sub
Private Sub MSHFlexGrid1_Db lClick()
FormUpdateSQL1. ViewRecord True, Val(MSHFlexGrid 1.Text)
End Sub
Jun 18 '08 #5
squrel
143 New Member
Is anyone can help me in this matter??
Jun 18 '08 #6
QVeen72
1,445 Recognized Expert Top Contributor

txtAddressId.Te xt = GetNextCode("Ad dress", "AdrID")
This looks like you are calling a Function...
and you may not have that Function in your code, and the Error is the same...

Regards
Veena
Jun 18 '08 #7
squrel
143 New Member
Hi
In this code how can i get the next Id?? I mean if i have 7 record saved in this, when i press the add button i want the no 8 appears in my txtId... Can anyone help me plz... thankx a lot
Jun 19 '08 #8
squrel
143 New Member
Hi Guys..
I need some help here if anyone can.. thankx
Jun 20 '08 #9
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

Write this Function :
{AIRCODE}

Expand|Select|Wrap|Line Numbers
  1. Private Function MyNextID() As Long
  2. Dim RSI As New ADODB.RecordSet
  3. MyNextID = 0
  4. RSI.Open "Select Max(ID) From MyTable",Conn
  5. If Not RSI.EOF Then
  6.     RSI.MoveFirst
  7.     MyNextID = Val(RSI(0) & "")
  8. End If
  9. MyNextID = MyNextID + 1
  10. RSI.Close
  11. Set RSI = Nothing
  12. End Function
  13.  
Call the above Function, In cmdADD_Click
Expand|Select|Wrap|Line Numbers
  1. txtID.Text = MyNextID
  2.  
Regards
Veena
Jun 20 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
9717
by: PK | last post by:
Hello, I am looking for help on the following. I'm trying to create a custom browser toolbar button that will do a few things. One that I'm trying to do at the moment is just simply return the URL of whatever page the user is visiting. I wanted to create a Win32 application using VB.NET. If there is a better way of doing this please let me know. I assume there needs to be some sort of client side code. I was originally leaning...
0
1612
by: jbbs | last post by:
I have a question regarding on the button and label. i don't know why when the mouse cursor points on the button, i see the button is flirking. is there anyway to make it not behave like that? because i want to highlight the text above the button when i click on it. can anyone help me out . Thank You the code is following: ############################################ # File: toolbar1.py
0
1815
by: Lauren Quantrell | last post by:
I use the following code to create text edit fields and command buttons in my toolbars: Function CreateToolbarObject(myObjectType as integer) Dim newObject Select Case myObjectType Case 1 'text Set newObject =
7
2825
by: IntraRELY | last post by:
I am using the following command to launch and .NET VB Executable, which is a simple Windows Form (printCheckClient.exe). I am using a HyperLink Control and works perfect. hlPrintChecks.NavigateUrl = "javascript:var newWindow =window.open('printCheckClient.exe', 1,'height=350,width=350,menubar=no,status=no,toolbar=no')" I want to use a standard ASP.NET Button, but not sure what method to use. Is there a way to accomplish this. I may not...
6
1795
by: jake | last post by:
How do you get or save a file from/to a client (button on web page) once they are authenticated? The client could be Mac, Linux or Windows. Can I do it all with IIS and ASP.NET?
8
1285
by: Mark Goldin | last post by:
I have a toolbar on my form. How do I know what button was clicked?
1
20162
by: reidarT | last post by:
I have entered a BindingNavigator toolbar in a bound form and can manage to browse records and I am able to enter data in a new record. I am ot able to save the data and therefore I have entered the save-button. How do I code this button to save a new record? reidarT
3
3686
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of html is: <a class="searchsavechanges btn btn3d tbbtn" href="javascript:" style="position:static"> <div id="TBsearchsavechanges">Search</div> </a>
4
2459
by: manjesh | last post by:
hi , kindly help to create a toolbar with that new , save , edit, cancel button , if i open each form to operate this buttons ,instead of placing in each form . regards manjesh
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.