Page 1 of 2 12 LastLast
Results 1 to 40 of 52

Thread: [RESOLVED] How to set current date..??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Resolved [RESOLVED] How to set current date..??

    Dear Experts,

    I am trying to make this following shymptoms:

    When I open this word document (current_date.doc), the form will automatically open and also automatically fill the current date with time in TextBox1....anyone could help me please to perform like this..???

    Please find my attached file for your reviews.

    Thanks very much for your helps.

    Best Regards,

    Jennifer
    Attached Files Attached Files

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: How to set current date..??

    Hi,

    Use the following code in your user form:

    VB Code:
    1. Private Sub UserForm_Initialize()
    2. TextBox1.Text = Date
    3. 'If you want to change the format of the date use format function
    4. 'TextBox1.Text = Format(Date, "DD-MMM-YYYY, HH:mm")
    5. 'If you want to display time with the format:
    6. 'TextBox1.Text = Format(Time, "hh:mm:ss")
    7. 'If you want to display both date and time you can use now function
    8. 'TextBox1.Text = Format(Now(), "DD-MMM-YYY hh:mm")
    9. End Sub
    _____________
    CS.
    Last edited by cssriraman; Dec 7th, 2005 at 02:25 AM.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to set current date..??

    One minor note. You do not need the parentheses with Now.
    VB Code:
    1. Text1.Text = Format(Now, ""DD-MMM-YYY hh:mm")

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: How to set current date..??

    Hi All,

    Thanks very much for your helps...However, I tried to use your codes but the year was not 2005...it is 3451 or something...what was wrong with it..???..Additionally, I can still write on the TextBox...How should I do in order me could not write anything/re-write on the TextBox1 please???.....Please find my attached file and have a look what was wrong with my codes please...

    Thank you for your kind helps...

    Best Regards,

    Jennifer
    Attached Files Attached Files

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: How to set current date..??

    What's the date format on your system? That looks like a Chinese or Jewish year, except they're something like 4702 & 5766, respectively.
    Tengo mas preguntas que contestas

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: How to set current date..??

    Hi All Experts,

    Have you open my file and look at it please..???...I just want to make sure the year will be 2005...not like this. i.e. 8-Dec-05342 8:48......Additionally, I can still write up on the TextBox1...what I would like trying to do is when the document is open, the form will automatically come up and show the current date and time on the TextBox1 and anyone could not changed/rewrite the date and time on that TextBox1 (it is looked like a disable for rewriting)...

    Anyone could help me for that please...please....

    Thanks for all your kind helpfulness...

    Best Regards,

    Jennifer
    Last edited by zach007; Dec 7th, 2005 at 07:52 PM.

  7. #7
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: How to set current date..??

    Check out the uploaded file.

    the date format should be like this:
    VB Code:
    1. 'To set the date and time in Textbox when loading the form
    2. TextBox1.Text = Format(Now, "DD-MMM-YYYY hh:mm")
    3.  
    4. 'not as
    5. 'TextBox1.Text = Format(Now, "DD-MMM-YYY hh:mm")
    6.  
    7. 'To restrict the user not to write in text box
    8. TextBox1.Locked = True
    Attached Files Attached Files
    CS

  8. #8
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: How to set current date..??

    Quote Originally Posted by Hack
    One minor note. You do not need the parentheses with Now.
    VB Code:
    1. Text1.Text = Format(Now, ""DD-MMM-YYY hh:mm")
    Oops!

    the date format in your code is wrong!

    should be
    VB Code:
    1. Text1.text =  Format(Now, "DD-MMM-YYYY hh:mm")
    CS

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: How to set current date..??

    Dear Experts,

    What additional code should I put if I would like to put a current date on bookmark directly rather than on TextBox....For an example, if I open my word document .i.e. testing.doc, it will automatically show current date on the bookmark....

    Anyone could help me please...???

    Thank you so much...

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to set current date..??

    VB Code:
    1. ActiveDocument.Bookmarks.Item("CurrentDate").Range.Text = Format(Now, "DD-MMM-YYYY hh:mm")
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: How to set current date..??

    Hi,

    I put this code into "ThisDocument"

    VB Code:
    1. ActiveDocument.Bookmarks.Item("bk_date").Range.Text = Format(Now, "DD-MMM-YYYY hh:mm")

    But still does not show up automatically when I open that word doc....

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to set current date..??

    In the Document_Open event?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: How to set current date..??

    Hi,

    I did this:

    VB Code:
    1. Private Sub Document_Open()
    2.  
    3. ActiveDocument.Bookmarks.Item("bk_date").Range.Text = Format(Now, "DD-MMM-YYYY hh:mm")
    4.  
    5. End Sub

    and received an error message: Run Time Error: '6028' The range cannot be deleted.


  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to set current date..??

    Does the bookmark exist in that document?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: How to set current date..??

    Yes, it is exist. When I save it. Then I re-open the word document then there is an error message: Run Time Errors '6028' - The range cannot be deleted.

    Please help me for this....

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to set current date..??

    Attach your most current document and I'll look at it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: How to set current date..??

    Hi,

    Thanks a lot for your helps...it is on section "Date of Issue" in word document...I make the bookmark invisible...so, you could double click on it to see the bookmark name which is "bk_date"....

    Additionally, on UserForm1, on Update Item tab, there is a "Check Current Stock" button...why with this button, I have to press it twice or more to get current data result..???..after I add stock....Would you please also help me for this..???...

    Please find my attached file....

    Thank you very much for your kind helps....
    Attached Files Attached Files

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to set current date..??

    Ok, I got it. Its giving that error from the bookmark being a Date format. you need to set the format of it from the properties context menu item when the bookmark is selected from the goto bookmark via the Insert > Bookmarks... dialog.

    Then type in the custom format that you have and it will work.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: How to set current date..??

    It works...!!!...Thanks a lot for your kind helps...???....How about the button that I asked to you..??

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    Oh, missed that part. I'll look.

    You could also format the bookmark as a Text field instead of a Date field too.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    Looks like your not refreshing your rst. Sorry if its a bit off as I'm tired and getting ready to call it a night.
    VB Code:
    1. Private Sub CommandButton3_Click()
    2.  
    3.     Dim con As ADODB.Connection
    4.     Set con = New ADODB.Connection
    5.     con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\exercise.mdb"
    6.     If Not TypeName(rst) = "Nothing" Then
    7.         'something
    8.         If rst.State = adStateOpen Then
    9.             'open
    10.             rst.Close
    11.             Set rst = Execute_SQL_ReturnRecordSet
    12.         Else
    13.             'closed
    14.             Set rst = Execute_SQL_ReturnRecordSet
    15.         End If
    16.     Else
    17.         'nothing
    18.         Set rst = Execute_SQL_ReturnRecordSet
    19.     End If
    20.     TextBox3.Text = rst.Fields("Qty")
    21.  
    22. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    Hi,

    That all right..thanks very much anyway...But, when those codes run, then it has a "compile error : Argument not optional" when at go to this part "Set rst = Execute_SQL_ReturnRecordSet".....

  23. #23
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    Oh, sorry. You need to pass the arguments to your function. I wasnt too familiar with your funciton.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  24. #24
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    Ok, I think this should do it. I was just going by your examples.
    VB Code:
    1. Private Sub CommandButton3_Click()
    2.  
    3.     Dim con As ADODB.Connection
    4.     Set con = New ADODB.Connection
    5.     con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\exercise.mdb"
    6.     If Not TypeName(rst) = "Nothing" Then
    7.         'something
    8.         If rst.State = adStateOpen Then
    9.             'open
    10.             rst.Close
    11.             Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
    12.         Else
    13.             'closed
    14.             Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
    15.         End If
    16.     Else
    17.         'nothing
    18.         Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
    19.     End If
    20.     TextBox3.Text = rst.Fields("Qty")
    21.  
    22. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    Hi,

    Sorry for that...but why NOW is getting worst....when I click "Check Current Stock", it always show the result "14"....

    and the worst is..when I click "Add Stock" button...before, it runs well without errors, now it has errors:

    VB Code:
    1. Private Sub cmdAddStock_Click()
    2.  
    3. Dim con As ADODB.Connection
    4. Set con = New ADODB.Connection
    5.   con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
    6.           & "c:\exercise.mdb"
    7.  
    8.  
    9.     'update the data
    10.     Dim strSQL As String
    11.         strSQL = "UPDATE item " _
    12.             & " SET Qty = Qty + " & TextBox5.Text _
    13.             & " WHERE Item_Code = " & Trim$(cmb_item)
    14.         con.Execute strSQL
    15.        
    16.                MsgBox "Your stock has been updated.", , "Update Stock Success"
    17.                TextBox3.Text = rst.Fields("Qty")
    18.        
    19.            
    20.        
    21.         Application.ScreenRefresh
    22.  
    23. End Sub

    and "con.Execute strSQL was yellow highlighted and errors: Syntax error (missing operator) in query expression 'Qty +'..???
    Last edited by zach007; Jan 14th, 2006 at 01:31 PM.

  26. #26
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    Probably because of the sql querystring. Not sure what your needing but this requeries the table and reloads the rst.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    Hi,

    It works for "Add Stock" button..that my mistakes...I forgot to put something there...BUT with "Check Current Stock" button, I really have no idea what is going on...it suppose to show current updated stock...BUT it keep show "14" which is the first row qty on the Item table...would you please have a look at my form and click it on "Check Current Stock" please...???...please....???....or if you are tired, you could check it tomorrow...I really stack......have you still got my file...????

    I really need your help...

    Thanks a lot....

  28. #28
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    14 would be the first record. Whats its supposed to show?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    It suppose to show on selected Item_code, then it will show its "Qty".....i.e. If I select Item_Code number 3, then it will show its qty....please help me for this code....
    Last edited by zach007; Jan 14th, 2006 at 11:29 PM.

  30. #30
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    Ok, then you will want to just move the recordset position to that record where the Item_Code matches the current Item_Code in the selected row on the form. You can do it with a loop and an rst.MoveNext with the test for match after that.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  31. #31

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    Hi,

    I tried many times...but still did not works...this is my last codes for "Check Current Stock":

    VB Code:
    1. Dim con As ADODB.Connection
    2.     Set con = New ADODB.Connection
    3.     con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\exercise.mdb"
    4.    
    5.       Dim x As Integer
    6.       Dim ItemCodes(10)
    7.        
    8.  
    9.        For x = 1 To rst.RecordCount
    10.         ItemCodes(x - 1) = rst.Fields("Item_Code").Value
    11.         Debug.Print rst.Fields("Item_Code").Value & " " & _
    12.             rst.Fields("Description").Value
    13.    
    14.     If Not TypeName(rst) = "Nothing" Then
    15.         'something
    16.         If rst.State = adStateOpen Then
    17.             'open
    18.             rst.Close
    19.             Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
    20.            
    21.         Else
    22.             'closed
    23.             Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
    24.         End If
    25.     Else
    26.         'nothing
    27.         Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
    28.     End If
    29.     TextBox3.Text = rst.Fields("Qty")
    30.  
    31.       rst.MoveNext
    32.     Next

    Could you please fix my code please....????...Because I dont know what should I do anymore....

    Thank you so much....

  32. #32
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    No, you cant just do a .MoveNext without evaluating which record the recordset is on.
    VB Code:
    1. rst.MoveFirst
    2. Do While rst.EOF = False
    3.     If UserForm1.txtQty.Text = rst.Fields("Item_Code").Value Then
    4.         Exit Do
    5.     End f
    6.     rst.MoveNext
    7. Loop
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  33. #33
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    Step through the code and see if your values are what you should be getting. Press F8 to step through the code after you place a breakpoint on Command3_Click and click the button.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  34. #34

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    Hi,

    I did this codes and follow your codes...but still error:
    VB Code:
    1. Private Sub CommandButton3_Click()
    2.  
    3.  Dim con As ADODB.Connection
    4.     Set con = New ADODB.Connection
    5.     con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\exercise.mdb"
    6.    
    7.          rst.MoveFirst
    8. Do While rst.EOF = False
    9.     If UserForm1.txtqty.Text = rst.Fields("Item_Code").Value Then
    10.         Exit Do
    11.     End If
    12.     rst.MoveNext
    13. Loop
    14. TextBox3.Text = rst.Fields("Qty")
    15.        
    16.     Application.ScreenRefresh
    17. End Sub

    and "TextBox3.Text = rst.Fields("Qty")" was in yellow highlighted...and error message like this: Run Time Error '3021' Either BOF is TRUE, or the current record has been deleted. Requested operation requires a current records.

    Would you please correcr my codes...????..

    Thank you so much....

  35. #35
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    I dont see where your opening your recordset rst? I had it in the code I posted. This is why your probably getting the 3021 error.
    VB Code:
    1. Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  36. #36

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    Hi,

    I did this codes, but still errors:

    VB Code:
    1. Private Sub CommandButton3_Click()
    2.  
    3.  Dim con As ADODB.Connection
    4.     Set con = New ADODB.Connection
    5.     con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\exercise.mdb"
    6.    
    7.     Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
    8.    
    9.          rst.MoveFirst
    10. Do While rst.EOF = False
    11.     If UserForm1.txtqty.Text = rst.Fields("Item_Code").Value Then
    12.        Exit Do
    13.     End If
    14.     rst.MoveNext
    15. Loop
    16.  
    17.     TextBox3.Text = rst.Fields("Qty")
    18.        
    19.     Application.ScreenRefresh
    20. End Sub

    When I select item no 1, then when I press "Check Current Stock" it show its Qty...BUT, when I select other item numbers, let say item code number 3 it still show the Qty for item number 1...???....

  37. #37
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] How to set current date..??

    My mistake. We are not comparing the correct fields. We need to cpmpare the Item_Code field with whatever control holds that value on the userform.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  38. #38

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    Could you please show me the code please..???..Because I really have no idea how to do that...

    Thanks very much....

  39. #39

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    Please help me for this codes...?????

  40. #40

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: [RESOLVED] How to set current date..??

    Dear Experts,

    Has anyone could help me please for these code?

    VB Code:
    1. Private Sub CommandButton3_Click()
    2.  
    3.  Dim con As ADODB.Connection
    4.     Set con = New ADODB.Connection
    5.     con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\exercise.mdb"
    6.    
    7.     Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")
    8.    
    9.          rst.MoveFirst
    10. Do While rst.EOF = False
    11.     If UserForm1.txtqty.Text = rst.Fields("Item_Code").Value Then
    12.        Exit Do
    13.     End If
    14.     rst.MoveNext
    15. Loop
    16.  
    17.     TextBox3.Text = rst.Fields("Qty")
    18.        
    19.     Application.ScreenRefresh
    20. End Sub

    When I select item no 1, then when I press "Check Current Stock" it show its Qty...BUT, when I select other item numbers, let say item code number 3 it still show the Qty for item number 1...???....

    Please help with code corrections...

    Thank you so much...

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width